Skip to content

Commit 690ed88

Browse files
bpo-46205: exit if no workers are alive in runtest_mp (GH-30470)
(cherry picked from commit e13cdca) Co-authored-by: Sam Gross <[email protected]>
1 parent b29aa71 commit 690ed88

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
@@ -396,16 +396,12 @@ def stop_workers(self) -> None:
396396
worker.wait_stopped(start_time)
397397

398398
def _get_result(self) -> QueueOutput | None:
399-
if not any(worker.is_alive() for worker in self.workers):
400-
# all worker threads are done: consume pending results
401-
try:
402-
return self.output.get(timeout=0)
403-
except queue.Empty:
404-
return None
405-
406399
use_faulthandler = (self.ns.timeout is not None)
407400
timeout = PROGRESS_UPDATE
408-
while True:
401+
402+
# bpo-46205: check the status of workers every iteration to avoid
403+
# waiting forever on an empty queue.
404+
while any(worker.is_alive() for worker in self.workers):
409405
if use_faulthandler:
410406
faulthandler.dump_traceback_later(MAIN_PROCESS_TIMEOUT,
411407
exit=True)
@@ -421,6 +417,12 @@ def _get_result(self) -> QueueOutput | None:
421417
if running and not self.ns.pgo:
422418
self.log('running: %s' % ', '.join(running))
423419

420+
# all worker threads are done: consume pending results
421+
try:
422+
return self.output.get(timeout=0)
423+
except queue.Empty:
424+
return None
425+
424426
def display_result(self, mp_result: MultiprocessResult) -> None:
425427
result = mp_result.result
426428

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)