[Python-checkins] bpo-46205: exit if no workers are alive in runtest_mp (GH-30470)

miss-islington webhook-mailer at python.org
Mon Jan 10 22:32:25 EST 2022


https://github.com/python/cpython/commit/690ed889c537c008a2c5f3e6c4f06c5b0c0afbc6
commit: 690ed889c537c008a2c5f3e6c4f06c5b0c0afbc6
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-01-10T19:32:15-08:00
summary:

bpo-46205: exit if no workers are alive in runtest_mp (GH-30470)

(cherry picked from commit e13cdca0f5224ec4e23bdd04bb3120506964bc8b)

Co-authored-by: Sam Gross <colesbury at gmail.com>

files:
A Misc/NEWS.d/next/Tests/2022-01-07-14-06-12.bpo-46205.dnc2OC.rst
M Lib/test/libregrtest/runtest_mp.py

diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py
index b9404d53d3ce7..cef877cbad8c8 100644
--- a/Lib/test/libregrtest/runtest_mp.py
+++ b/Lib/test/libregrtest/runtest_mp.py
@@ -396,16 +396,12 @@ def stop_workers(self) -> None:
             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)
@@ -421,6 +417,12 @@ def _get_result(self) -> QueueOutput | None:
             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
index 0000000000000..7c6121fb16249
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2022-01-07-14-06-12.bpo-46205.dnc2OC.rst
@@ -0,0 +1 @@
+Fix hang in runtest_mp due to race condition



More information about the Python-checkins mailing list