]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-130954: Fix multiprocessing test_notify_n (GH-130955) (#130981)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 8 Mar 2025 18:28:07 +0000 (19:28 +0100)
committerGitHub <noreply@github.com>
Sat, 8 Mar 2025 18:28:07 +0000 (18:28 +0000)
The test could deadlock trying join on the worker processes.
Apply the same technique as gh-130933.

Join the process before the test ends in `test_notify` as well.
(cherry picked from commit edd1eca336976b3431cf636aea87f08a40c94935)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Lib/test/_test_multiprocessing.py

index e766bd5feba820f249e0c86c28b4f597ccc138cb..4b06123011cb66fab365a14477d5beb7adb59038 100644 (file)
@@ -1609,12 +1609,10 @@ class _TestCondition(BaseTestCase):
         p = self.Process(target=self.f, args=(cond, sleeping, woken))
         p.daemon = True
         p.start()
-        self.addCleanup(p.join)
 
-        p = threading.Thread(target=self.f, args=(cond, sleeping, woken))
-        p.daemon = True
-        p.start()
-        self.addCleanup(p.join)
+        t = threading.Thread(target=self.f, args=(cond, sleeping, woken))
+        t.daemon = True
+        t.start()
 
         # wait for both children to start sleeping
         sleeping.acquire()
@@ -1641,7 +1639,9 @@ class _TestCondition(BaseTestCase):
 
         # check state is not mucked up
         self.check_invariant(cond)
-        p.join()
+
+        threading_helper.join_thread(t)
+        join_process(p)
 
     def test_notify_all(self):
         cond = self.Condition()
@@ -1718,16 +1718,17 @@ class _TestCondition(BaseTestCase):
         woken = self.Semaphore(0)
 
         # start some threads/processes
+        workers = []
         for i in range(3):
             p = self.Process(target=self.f, args=(cond, sleeping, woken))
             p.daemon = True
             p.start()
-            self.addCleanup(p.join)
+            workers.append(p)
 
             t = threading.Thread(target=self.f, args=(cond, sleeping, woken))
             t.daemon = True
             t.start()
-            self.addCleanup(t.join)
+            workers.append(t)
 
         # wait for them to all sleep
         for i in range(6):
@@ -1762,6 +1763,10 @@ class _TestCondition(BaseTestCase):
         # check state is not mucked up
         self.check_invariant(cond)
 
+        for w in workers:
+            # NOTE: join_process and join_thread are the same
+            threading_helper.join_thread(w)
+
     def test_timeout(self):
         cond = self.Condition()
         wait = TimingWrapper(cond.wait)