@@ -465,10 +465,18 @@ def start(self):
465465 async def join (self , timeout = None ):
466466 """Wait for the process to exit"""
467467 with ThreadPoolExecutor (1 ) as pool :
468+ wait = partial (self .process .wait , timeout )
468469 try :
469- await asyncio .wrap_future (
470- pool .submit (partial (self .process .wait , timeout ))
471- )
470+ try :
471+ future = pool .submit (wait )
472+ except RuntimeError :
473+ # e.g. called during process shutdown,
474+ # which raises
475+ # RuntimeError: cannot schedule new futures after interpreter shutdown
476+ # Instead, do the blocking call
477+ wait ()
478+ else :
479+ await asyncio .wrap_future (future )
472480 except psutil .TimeoutExpired :
473481 raise TimeoutError (
474482 f"Process { self .pid } did not complete in { timeout } seconds."
@@ -1184,9 +1192,17 @@ def wait_one(self, timeout):
11841192
11851193 async def join (self , timeout = None ):
11861194 with ThreadPoolExecutor (1 ) as pool :
1187- await asyncio .wrap_future (
1188- pool .submit (partial (self .wait_one , timeout = timeout ))
1189- )
1195+ wait = partial (self .wait_one , timeout = timeout )
1196+ try :
1197+ future = pool .submit (wait )
1198+ except RuntimeError :
1199+ # e.g. called during process shutdown,
1200+ # which raises
1201+ # RuntimeError: cannot schedule new futures after interpreter shutdown
1202+ # Instead, do the blocking call
1203+ wait ()
1204+ else :
1205+ await asyncio .wrap_future (future )
11901206
11911207 def signal (self , sig ):
11921208 if self .state == 'running' :
0 commit comments