Skip to content

Commit 61c0a8f

Browse files
committed
Use execnet main_thread_only execmodel
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work. This execmodel has been merged to the execnet master branch via pytest-dev/execnet#243, so this patch should not be merged until there is a released version of execnet supporting the main_thread_only execmodel. Also increase minimum python version to 3.8 since execnet dropped 3.7 support in pytest-dev/execnet#245. Closes: #620
1 parent f57c658 commit 61c0a8f

File tree

8 files changed

+17
-12
lines changed

8 files changed

+17
-12
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ jobs:
3434
fail-fast: false
3535
matrix:
3636
tox_env:
37-
- "py37-pytestlatest"
3837
- "py38-pytestlatest"
3938
- "py39-pytestlatest"
4039
- "py310-pytestlatest"
@@ -46,8 +45,6 @@ jobs:
4645

4746
os: [ubuntu-latest, windows-latest]
4847
include:
49-
- tox_env: "py37-pytestlatest"
50-
python: "3.7"
5148
- tox_env: "py38-pytestlatest"
5249
python: "3.8"
5350
- tox_env: "py39-pytestlatest"

changelog/620.bugfix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Use the execnet main_thread_only execmodel so that code which expects to run in the main thread will just work.
2+
3+
Also increase minimum python version to 3.8 since execnet dropped 3.7 support in pytest-dev/execnet#245.

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ classifiers = [
2525
"Programming Language :: Python",
2626
"Programming Language :: Python :: 3",
2727
"Programming Language :: Python :: 3 :: Only",
28-
"Programming Language :: Python :: 3.7",
2928
"Programming Language :: Python :: 3.8",
3029
"Programming Language :: Python :: 3.9",
3130
"Programming Language :: Python :: 3.10",
3231
"Programming Language :: Python :: 3.11",
3332
"Programming Language :: Python :: 3.12",
3433
]
35-
requires-python = ">=3.7"
34+
requires-python = ">=3.8"
3635
dependencies = [
37-
"execnet>=1.1",
36+
"execnet@git+https://github.com/pytest-dev/execnet#egg=master",
3837
"pytest>=6.2.0",
3938
]
4039
dynamic = ["version"]

src/xdist/looponfail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def trace(self, *args):
7676
print("RemoteControl:", msg)
7777

7878
def initgateway(self):
79-
return execnet.makegateway("popen")
79+
return execnet.makegateway("execmodel=main_thread_only//popen")
8080

8181
def setup(self, out=None):
8282
if out is None:

src/xdist/workermanage.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ def __init__(self, config, specs=None, defaultchdir="pyexecnetcache") -> None:
4141
self.testrunuid = self.config.getoption("testrunuid")
4242
if self.testrunuid is None:
4343
self.testrunuid = uuid.uuid4().hex
44-
self.group = execnet.Group()
44+
self.group = execnet.Group(execmodel="main_thread_only")
4545
if specs is None:
4646
specs = self._getxspecs()
4747
self.specs = []
4848
for spec in specs:
4949
if not isinstance(spec, execnet.XSpec):
5050
spec = execnet.XSpec(spec)
51+
if getattr(spec, "execmodel", None) != "main_thread_only":
52+
spec = execnet.XSpec(f"execmodel=main_thread_only//{spec}")
5153
if not spec.chdir and not spec.popen:
5254
spec.chdir = defaultchdir
5355
self.group.allocate_id(spec)
@@ -68,6 +70,10 @@ def setup_nodes(self, putevent):
6870
return [self.setup_node(spec, putevent) for spec in self.specs]
6971

7072
def setup_node(self, spec, putevent):
73+
if not isinstance(spec, execnet.XSpec):
74+
spec = execnet.XSpec(spec)
75+
if getattr(spec, "execmodel", None) != "main_thread_only":
76+
spec = execnet.XSpec(f"execmodel=main_thread_only//{spec}")
7177
gw = self.group.makegateway(spec)
7278
self.config.hook.pytest_xdist_newgateway(gateway=gw)
7379
self.rsync_roots(gw)

testing/test_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self, request, pytester: pytest.Pytester) -> None:
3838
def setup(self) -> None:
3939
self.pytester.chdir()
4040
# import os ; os.environ['EXECNET_DEBUG'] = "2"
41-
self.gateway = execnet.makegateway()
41+
self.gateway = execnet.makegateway("execmodel=main_thread_only//popen")
4242
self.config = config = self.pytester.parseconfigure()
4343
putevent = self.events.put if self.use_callback else None
4444

testing/test_workermanage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_popen_makegateway_events(
7272
assert len(call.specs) == 2
7373

7474
call = hookrecorder.popcall("pytest_xdist_newgateway")
75-
assert call.gateway.spec == execnet.XSpec("popen")
75+
assert call.gateway.spec == execnet.XSpec("execmodel=main_thread_only//popen")
7676
assert call.gateway.id == "gw0"
7777
call = hookrecorder.popcall("pytest_xdist_newgateway")
7878
assert call.gateway.id == "gw1"
@@ -162,7 +162,7 @@ def test_hrsync_filter(self, source: Path, dest: Path) -> None:
162162
assert names == {"dir", "file.txt", "somedir"}
163163

164164
def test_hrsync_one_host(self, source: Path, dest: Path) -> None:
165-
gw = execnet.makegateway("popen//chdir=%s" % dest)
165+
gw = execnet.makegateway("execmodel=main_thread_only//popen//chdir=%s" % dest)
166166
finished = []
167167
rsync = HostRSync(source)
168168
rsync.add_target_host(gw, finished=lambda: finished.append(1))

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
envlist=
33
linting
4-
py{37,38,39,310,311,312}-pytestlatest
4+
py{38,39,310,311,312}-pytestlatest
55
py310-pytestmain
66
py310-psutil
77
py310-setproctitle

0 commit comments

Comments
 (0)