]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46205: exit if no workers are alive in runtest_mp (GH-30470)
authorSam Gross <colesbury@gmail.com>
Tue, 11 Jan 2022 03:03:09 +0000 (22:03 -0500)
committerGitHub <noreply@github.com>
Tue, 11 Jan 2022 03:03:09 +0000 (12:03 +0900)
Lib/test/libregrtest/runtest_mp.py
Misc/NEWS.d/next/Tests/2022-01-07-14-06-12.bpo-46205.dnc2OC.rst [new file with mode: 0644]

index f02f56e98bcda261f827d7c47f63bfffbbe65c01..75444e48080ce5ac6de440f0adc792ef067b2849 100644 (file)
@@ -392,16 +392,12 @@ class MultiprocessTestRunner:
             worker.wait_stopped(start_time)
 
     def _get_result(self) -> QueueOutput | None:
-        if not any(worker.is_alive() for worker in self.workers):
-            # all worker threads are done: consume pending results
-            try:
-                return self.output.get(timeout=0)
-            except queue.Empty:
-                return None
-
         use_faulthandler = (self.ns.timeout is not None)
         timeout = PROGRESS_UPDATE
-        while True:
+
+        # bpo-46205: check the status of workers every iteration to avoid
+        # waiting forever on an empty queue.
+        while any(worker.is_alive() for worker in self.workers):
             if use_faulthandler:
                 faulthandler.dump_traceback_later(MAIN_PROCESS_TIMEOUT,
                                                   exit=True)
@@ -417,6 +413,12 @@ class MultiprocessTestRunner:
             if running and not self.ns.pgo:
                 self.log('running: %s' % ', '.join(running))
 
+        # all worker threads are done: consume pending results
+        try:
+            return self.output.get(timeout=0)
+        except queue.Empty:
+            return None
+
     def display_result(self, mp_result: MultiprocessResult) -> None:
         result = mp_result.result
 
diff --git a/Misc/NEWS.d/next/Tests/2022-01-07-14-06-12.bpo-46205.dnc2OC.rst b/Misc/NEWS.d/next/Tests/2022-01-07-14-06-12.bpo-46205.dnc2OC.rst
new file mode 100644 (file)
index 0000000..7c6121f
--- /dev/null
@@ -0,0 +1 @@
+Fix hang in runtest_mp due to race condition