Skip to content

Commit 4e7bd02

Browse files
Avoid unnecessary rinfo calls after creating gateways (#909)
Hopefully this fixes #907, as seems this is the only change in #901 which is somehow related. --------- Co-authored-by: Ronny Pfannschmidt <[email protected]>
1 parent 52a6143 commit 4e7bd02

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

Diff for: changelog/907.bugfix.rst

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Avoid remote calls during startup as ``execnet`` by default does not ensure remote affinity with the
2+
main thread and might accidentally schedule the pytest worker into a non-main thread, which breaks numerous frameworks,
3+
for example ``asyncio``, ``anyio``, ``PyQt/PySide``, etc.
4+
5+
A more safe correction will require thread affinity in ``execnet`` (`pytest-dev/execnet#96 <https://github.com/pytest-dev/execnet/issues/96>`__).

Diff for: src/xdist/dsession.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -444,26 +444,25 @@ def pytest_xdist_setupnodes(self, specs) -> None:
444444

445445
@pytest.hookimpl
446446
def pytest_xdist_newgateway(self, gateway) -> None:
447-
rinfo = gateway._rinfo()
448-
is_local = rinfo.executable == sys.executable
449-
if self.config.option.verbose > 0 and not is_local:
450-
version = "%s.%s.%s" % rinfo.version_info[:3]
451-
self.rewrite(
452-
"[%s] %s Python %s cwd: %s"
453-
% (gateway.id, rinfo.platform, version, rinfo.cwd),
454-
newline=True,
455-
)
447+
if self.config.option.verbose > 0:
448+
rinfo = gateway._rinfo()
449+
different_interpreter = rinfo.executable != sys.executable
450+
if different_interpreter:
451+
version = "%s.%s.%s" % rinfo.version_info[:3]
452+
self.rewrite(
453+
f"[{gateway.id}] {rinfo.platform} Python {version} cwd: {rinfo.cwd}",
454+
newline=True,
455+
)
456456
self.setstatus(gateway.spec, WorkerStatus.Initialized, tests_collected=0)
457457

458458
@pytest.hookimpl
459459
def pytest_testnodeready(self, node) -> None:
460-
d = node.workerinfo
461-
is_local = d.get("executable") == sys.executable
462-
if self.config.option.verbose > 0 and not is_local:
463-
infoline = "[{}] Python {}".format(
464-
d["id"], d["version"].replace("\n", " -- ")
465-
)
466-
self.rewrite(infoline, newline=True)
460+
if self.config.option.verbose > 0:
461+
d = node.workerinfo
462+
different_interpreter = d.get("executable") != sys.executable
463+
if different_interpreter:
464+
version = d["version"].replace("\n", " -- ")
465+
self.rewrite(f"[{d['id']}] Python {version}", newline=True)
467466
self.setstatus(
468467
node.gateway.spec, WorkerStatus.ReadyForCollection, tests_collected=0
469468
)

0 commit comments

Comments
 (0)