Skip to content

Commit

Permalink
Avoid unnecessary rinfo calls after creating gateways (#909)
Browse files Browse the repository at this point in the history
Hopefully this fixes #907, as seems this is the only
change in #901 which is somehow related.

---------

Co-authored-by: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de>
  • Loading branch information
nicoddemus and RonnyPfannschmidt authored May 19, 2023
1 parent 52a6143 commit 4e7bd02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
5 changes: 5 additions & 0 deletions changelog/907.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Avoid remote calls during startup as ``execnet`` by default does not ensure remote affinity with the
main thread and might accidentally schedule the pytest worker into a non-main thread, which breaks numerous frameworks,
for example ``asyncio``, ``anyio``, ``PyQt/PySide``, etc.

A more safe correction will require thread affinity in ``execnet`` (`pytest-dev/execnet#96 <https://github.com/pytest-dev/execnet/issues/96>`__).
31 changes: 15 additions & 16 deletions src/xdist/dsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,26 +444,25 @@ def pytest_xdist_setupnodes(self, specs) -> None:

@pytest.hookimpl
def pytest_xdist_newgateway(self, gateway) -> None:
rinfo = gateway._rinfo()
is_local = rinfo.executable == sys.executable
if self.config.option.verbose > 0 and not is_local:
version = "%s.%s.%s" % rinfo.version_info[:3]
self.rewrite(
"[%s] %s Python %s cwd: %s"
% (gateway.id, rinfo.platform, version, rinfo.cwd),
newline=True,
)
if self.config.option.verbose > 0:
rinfo = gateway._rinfo()
different_interpreter = rinfo.executable != sys.executable
if different_interpreter:
version = "%s.%s.%s" % rinfo.version_info[:3]
self.rewrite(
f"[{gateway.id}] {rinfo.platform} Python {version} cwd: {rinfo.cwd}",
newline=True,
)
self.setstatus(gateway.spec, WorkerStatus.Initialized, tests_collected=0)

@pytest.hookimpl
def pytest_testnodeready(self, node) -> None:
d = node.workerinfo
is_local = d.get("executable") == sys.executable
if self.config.option.verbose > 0 and not is_local:
infoline = "[{}] Python {}".format(
d["id"], d["version"].replace("\n", " -- ")
)
self.rewrite(infoline, newline=True)
if self.config.option.verbose > 0:
d = node.workerinfo
different_interpreter = d.get("executable") != sys.executable
if different_interpreter:
version = d["version"].replace("\n", " -- ")
self.rewrite(f"[{d['id']}] Python {version}", newline=True)
self.setstatus(
node.gateway.spec, WorkerStatus.ReadyForCollection, tests_collected=0
)
Expand Down

0 comments on commit 4e7bd02

Please sign in to comment.