aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/_test_multiprocessing.py
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2025-03-08 13:04:30 -0500
committerGitHub <noreply@github.com>2025-03-08 13:04:30 -0500
commitedd1eca336976b3431cf636aea87f08a40c94935 (patch)
tree58efb0a699fa4ddd63ed4e41b81265c901f6b283 /Lib/test/_test_multiprocessing.py
parent72e5b25efb580fb1f0fdfade516be90d90822164 (diff)
downloadcpython-edd1eca336976b3431cf636aea87f08a40c94935.tar.gz
cpython-edd1eca336976b3431cf636aea87f08a40c94935.zip
gh-130954: Fix multiprocessing test_notify_n (#130955)
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.
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r--Lib/test/_test_multiprocessing.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 10c17b2dc7d..dcce57629ef 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -1654,12 +1654,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()
@@ -1686,7 +1684,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()
@@ -1763,16 +1763,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):
@@ -1807,6 +1808,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)