Skip to content

Commit a98a6bd

Browse files
authored
gh-129401: Test repr rlock failing randomly (#129959)
Fix and simplify a test of `test_repr_rlock` about multiprocessing.RLock primitive.
1 parent 5326c27 commit a98a6bd

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
@@ -1521,14 +1521,11 @@ def test_repr_rlock(self):
15211521
for i in range(n):
15221522
self.assertIn(f'<RLock(MainProcess|T{i+1}, {i+1})>', l)
15231523

1524-
1525-
t = threading.Thread(target=self._acquire_release,
1526-
args=(lock, 0.2),
1527-
name=f'T1')
1524+
rlock = self.RLock()
1525+
t = threading.Thread(target=rlock.acquire)
15281526
t.start()
1529-
time.sleep(0.1)
1530-
self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(lock))
1531-
time.sleep(0.2)
1527+
t.join()
1528+
self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(rlock))
15321529

15331530
pname = 'P1'
15341531
l = multiprocessing.Manager().list()
@@ -1539,14 +1536,11 @@ def test_repr_rlock(self):
15391536
p.join()
15401537
self.assertEqual(f'<RLock({pname}, 1)>', l[0])
15411538

1542-
event = self.Event()
1543-
lock = self.RLock()
1544-
p = self.Process(target=self._acquire_event,
1545-
args=(lock, event))
1539+
rlock = self.RLock()
1540+
p = self.Process(target=self._acquire, args=(rlock,))
15461541
p.start()
1547-
event.wait()
1548-
self.assertEqual('<RLock(SomeOtherProcess, nonzero)>', repr(lock))
15491542
p.join()
1543+
self.assertEqual('<RLock(SomeOtherProcess, nonzero)>', repr(rlock))
15501544

15511545
def test_rlock(self):
15521546
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)