@@ -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.
0 commit comments