Skip to content

Commit fead51d

Browse files
[3.13] gh-130954: Fix multiprocessing test_notify_n (GH-130955) (#130981)
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 edd1eca) Co-authored-by: Sam Gross <[email protected]>
1 parent 14230cd commit fead51d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,12 +1609,10 @@ def test_notify(self):
16091609
p = self.Process(target=self.f, args=(cond, sleeping, woken))
16101610
p.daemon = True
16111611
p.start()
1612-
self.addCleanup(p.join)
16131612

1614-
p = threading.Thread(target=self.f, args=(cond, sleeping, woken))
1615-
p.daemon = True
1616-
p.start()
1617-
self.addCleanup(p.join)
1613+
t = threading.Thread(target=self.f, args=(cond, sleeping, woken))
1614+
t.daemon = True
1615+
t.start()
16181616

16191617
# wait for both children to start sleeping
16201618
sleeping.acquire()
@@ -1641,7 +1639,9 @@ def test_notify(self):
16411639

16421640
# check state is not mucked up
16431641
self.check_invariant(cond)
1644-
p.join()
1642+
1643+
threading_helper.join_thread(t)
1644+
join_process(p)
16451645

16461646
def test_notify_all(self):
16471647
cond = self.Condition()
@@ -1718,16 +1718,17 @@ def test_notify_n(self):
17181718
woken = self.Semaphore(0)
17191719

17201720
# start some threads/processes
1721+
workers = []
17211722
for i in range(3):
17221723
p = self.Process(target=self.f, args=(cond, sleeping, woken))
17231724
p.daemon = True
17241725
p.start()
1725-
self.addCleanup(p.join)
1726+
workers.append(p)
17261727

17271728
t = threading.Thread(target=self.f, args=(cond, sleeping, woken))
17281729
t.daemon = True
17291730
t.start()
1730-
self.addCleanup(t.join)
1731+
workers.append(t)
17311732

17321733
# wait for them to all sleep
17331734
for i in range(6):
@@ -1762,6 +1763,10 @@ def test_notify_n(self):
17621763
# check state is not mucked up
17631764
self.check_invariant(cond)
17641765

1766+
for w in workers:
1767+
# NOTE: join_process and join_thread are the same
1768+
threading_helper.join_thread(w)
1769+
17651770
def test_timeout(self):
17661771
cond = self.Condition()
17671772
wait = TimingWrapper(cond.wait)

0 commit comments

Comments
 (0)