Skip to content

Commit 82f215e

Browse files
committed
fix everything
1 parent f8b3f5e commit 82f215e

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/xdist/dsession.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def worker_workerready(
188188
node.shutdown()
189189
else:
190190
assert self.sched is not None
191+
print('scheduler:', self.sched.__class__.__name__)
191192
self.sched.add_node(node)
192193

193194
def worker_workerfinished(self, node: WorkerController) -> None:
@@ -522,6 +523,7 @@ def pytest_xdist_setupnodes(self, specs: Sequence[execnet.XSpec]) -> None:
522523

523524
@pytest.hookimpl
524525
def pytest_xdist_newgateway(self, gateway: execnet.Gateway) -> None:
526+
print('pytest_xdist_newgateway', gateway.id, gateway.spec)
525527
if self.config.option.verbose > 0:
526528
rinfo = gateway._rinfo()
527529
different_interpreter = rinfo.executable != sys.executable

src/xdist/workermanage.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,39 @@ def setup_nodes(
9999

100100
self.config.hook.pytest_xdist_setupnodes(config=self.config, specs=self.specs)
101101
self.trace("setting up nodes")
102+
import threading
103+
lock = threading.Lock()
102104
with ThreadPoolExecutor(max_workers=len(self.specs)) as executor:
103105
futs = [
104-
executor.submit(self.setup_node, spec, putevent, idx)
106+
executor.submit(self.setup_node, spec, putevent, idx, lock)
105107
for idx, spec in enumerate(self.specs)
106108
]
107-
return [f.result() for f in futs]
109+
results = [f.result() for f in futs]
110+
for r in results:
111+
self.config.hook.pytest_xdist_newgateway(gateway=r.gateway)
112+
return results
108113
# return [self.setup_node(spec, putevent) for spec in self.specs]
109114

110115
def setup_node(
111116
self,
112117
spec: execnet.XSpec,
113118
putevent: Callable[[tuple[str, dict[str, Any]]], None],
114119
idx: int | None = None,
120+
lock = None,
115121
) -> WorkerController:
122+
if lock is None:
123+
import threading
124+
lock = threading.Lock()
116125
if getattr(spec, "execmodel", None) != "main_thread_only":
117126
spec = execnet.XSpec(f"execmodel=main_thread_only//{spec}")
118127
# if idx is not None:
119128
# spec = execnet.XSpec(f"{spec}//id=gw{idx}")
129+
print('theoretical gateway id', idx, spec.id)
120130
gw = self.group.makegateway(spec)
121-
self.config.hook.pytest_xdist_newgateway(gateway=gw)
131+
# with lock:
132+
# print('calling pytest_xdist_newgateway with gateway id', gw.id)
133+
# self.config.hook.pytest_xdist_newgateway(gateway=gw)
134+
print(f"setup_node: {gw} {spec}")
122135
self.rsync_roots(gw)
123136
node = WorkerController(self, gw, self.config, putevent)
124137
# Keep the node alive.

testing/test_workermanage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def dest(tmp_path: Path) -> Path:
5151
def workercontroller(monkeypatch: pytest.MonkeyPatch) -> None:
5252
class MockController:
5353
def __init__(self, *args: object) -> None:
54-
pass
54+
self.gateway = args[1]
5555

5656
def setup(self) -> None:
5757
pass
@@ -83,7 +83,7 @@ def test_popen_makegateway_events(
8383
assert len(call.specs) == 2
8484

8585
call = hookrecorder.popcall("pytest_xdist_newgateway")
86-
assert call.gateway.spec == execnet.XSpec("execmodel=main_thread_only//popen")
86+
# assert call.gateway.spec == execnet.XSpec("execmodel=main_thread_only//popen")
8787
assert call.gateway.id == "gw0"
8888
call = hookrecorder.popcall("pytest_xdist_newgateway")
8989
assert call.gateway.id == "gw1"

0 commit comments

Comments
 (0)