Skip to content

Commit bb1247d

Browse files
[3.13] gh-129401: Test repr rlock failing randomly (GH-129959) (#144405)
Fix and simplify a test of `test_repr_rlock` about multiprocessing.RLock primitive. (cherry picked from commit a98a6bd) Co-authored-by: Duprat <yduprat@gmail.com>
1 parent 54ece4b commit bb1247d

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,14 +1484,11 @@ def test_repr_rlock(self):
14841484
for i in range(n):
14851485
self.assertIn(f'<RLock(MainProcess|T{i+1}, {i+1})>', l)
14861486

1487-
1488-
t = threading.Thread(target=self._acquire_release,
1489-
args=(lock, 0.2),
1490-
name=f'T1')
1487+
rlock = self.RLock()
1488+
t = threading.Thread(target=rlock.acquire)
14911489
t.start()
1492-
time.sleep(0.1)
1493-
self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(lock))
1494-
time.sleep(0.2)
1490+
t.join()
1491+
self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(rlock))
14951492

14961493
pname = 'P1'
14971494
l = multiprocessing.Manager().list()
@@ -1502,14 +1499,11 @@ def test_repr_rlock(self):
15021499
p.join()
15031500
self.assertEqual(f'<RLock({pname}, 1)>', l[0])
15041501

1505-
event = self.Event()
1506-
lock = self.RLock()
1507-
p = self.Process(target=self._acquire_event,
1508-
args=(lock, event))
1502+
rlock = self.RLock()
1503+
p = self.Process(target=self._acquire, args=(rlock,))
15091504
p.start()
1510-
event.wait()
1511-
self.assertEqual('<RLock(SomeOtherProcess, nonzero)>', repr(lock))
15121505
p.join()
1506+
self.assertEqual('<RLock(SomeOtherProcess, nonzero)>', repr(rlock))
15131507

15141508
def test_rlock(self):
15151509
lock = self.RLock()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a flaky test in ``test_repr_rlock`` that checks the representation of :class:`multiprocessing.RLock`.

0 commit comments

Comments
 (0)