Skip to content

Commit e13cdca

Browse files
authored
bpo-46205: exit if no workers are alive in runtest_mp (GH-30470)
1 parent 081a214 commit e13cdca

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Lib/test/libregrtest/runtest_mp.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,12 @@ def stop_workers(self) -> None:
392392
worker.wait_stopped(start_time)
393393

394394
def _get_result(self) -> QueueOutput | None:
395-
if not any(worker.is_alive() for worker in self.workers):
396-
# all worker threads are done: consume pending results
397-
try:
398-
return self.output.get(timeout=0)
399-
except queue.Empty:
400-
return None
401-
402395
use_faulthandler = (self.ns.timeout is not None)
403396
timeout = PROGRESS_UPDATE
404-
while True:
397+
398+
# bpo-46205: check the status of workers every iteration to avoid
399+
# waiting forever on an empty queue.
400+
while any(worker.is_alive() for worker in self.workers):
405401
if use_faulthandler:
406402
faulthandler.dump_traceback_later(MAIN_PROCESS_TIMEOUT,
407403
exit=True)
@@ -417,6 +413,12 @@ def _get_result(self) -> QueueOutput | None:
417413
if running and not self.ns.pgo:
418414
self.log('running: %s' % ', '.join(running))
419415

416+
# all worker threads are done: consume pending results
417+
try:
418+
return self.output.get(timeout=0)
419+
except queue.Empty:
420+
return None
421+
420422
def display_result(self, mp_result: MultiprocessResult) -> None:
421423
result = mp_result.result
422424

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix hang in runtest_mp due to race condition

0 commit comments

Comments
 (0)