@@ -465,10 +465,18 @@ def start(self):
465
465
async def join (self , timeout = None ):
466
466
"""Wait for the process to exit"""
467
467
with ThreadPoolExecutor (1 ) as pool :
468
+ wait = partial (self .process .wait , timeout )
468
469
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 )
472
480
except psutil .TimeoutExpired :
473
481
raise TimeoutError (
474
482
f"Process { self .pid } did not complete in { timeout } seconds."
@@ -1184,9 +1192,17 @@ def wait_one(self, timeout):
1184
1192
1185
1193
async def join (self , timeout = None ):
1186
1194
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 )
1190
1206
1191
1207
def signal (self , sig ):
1192
1208
if self .state == 'running' :
0 commit comments