From c060eb33552822c3acc31045f3e939cf9e0bdd51 Mon Sep 17 00:00:00 2001 From: "Yves.Duprat" Date: Sun, 9 Feb 2025 18:28:48 +0100 Subject: [PATCH 1/4] Initial commit --- Lib/test/_test_multiprocessing.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 4b7c3e7fa8bdd7..16e1badc8720fe 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -1496,6 +1496,12 @@ def _acquire_release(lock, timeout, l=None, n=1): for _ in range(n): lock.release() + @staticmethod + def _acquire_and_wait(lock, barrier, timeout=.1): + lock.acquire() + barrier.wait() + time.sleep(timeout) + def test_repr_rlock(self): if self.TYPE != 'processes': self.skipTest('test not appropriate for {}'.format(self.TYPE)) @@ -1521,14 +1527,14 @@ def test_repr_rlock(self): for i in range(n): self.assertIn(f'', l) - - t = threading.Thread(target=self._acquire_release, - args=(lock, 0.2), - name=f'T1') + rlock = self.RLock() + barrier = self.Barrier(2) + t = threading.Thread(target=self._acquire_and_wait, + args=(rlock, barrier, .2)) t.start() - time.sleep(0.1) - self.assertEqual('', repr(lock)) - time.sleep(0.2) + barrier.wait() + self.assertEqual('', repr(rlock)) + t.join() pname = 'P1' l = multiprocessing.Manager().list() @@ -1539,12 +1545,12 @@ def test_repr_rlock(self): p.join() self.assertEqual(f'', l[0]) - event = self.Event() + barrier = self.Barrier(2) lock = self.RLock() - p = self.Process(target=self._acquire_event, - args=(lock, event)) + p = self.Process(target=self._acquire_and_wait, + args=(lock, barrier, .2)) p.start() - event.wait() + barrier.wait() self.assertEqual('', repr(lock)) p.join() From a0471ca985572b79dc46441dcff9650b9dbdbe30 Mon Sep 17 00:00:00 2001 From: "Yves.Duprat" Date: Mon, 10 Feb 2025 13:07:34 +0100 Subject: [PATCH 2/4] WIP --- Lib/test/_test_multiprocessing.py | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index 16e1badc8720fe..4b7e6445e16930 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -1496,12 +1496,6 @@ def _acquire_release(lock, timeout, l=None, n=1): for _ in range(n): lock.release() - @staticmethod - def _acquire_and_wait(lock, barrier, timeout=.1): - lock.acquire() - barrier.wait() - time.sleep(timeout) - def test_repr_rlock(self): if self.TYPE != 'processes': self.skipTest('test not appropriate for {}'.format(self.TYPE)) @@ -1528,13 +1522,10 @@ def test_repr_rlock(self): self.assertIn(f'', l) rlock = self.RLock() - barrier = self.Barrier(2) - t = threading.Thread(target=self._acquire_and_wait, - args=(rlock, barrier, .2)) + t = threading.Thread(target=rlock.acquire) t.start() - barrier.wait() - self.assertEqual('', repr(rlock)) t.join() + self.assertEqual('', repr(rlock)) pname = 'P1' l = multiprocessing.Manager().list() @@ -1545,14 +1536,11 @@ def test_repr_rlock(self): p.join() self.assertEqual(f'', l[0]) - barrier = self.Barrier(2) - lock = self.RLock() - p = self.Process(target=self._acquire_and_wait, - args=(lock, barrier, .2)) + rlock = self.RLock() + p = self.Process(target=self._acquire, args=(rlock,)) p.start() - barrier.wait() - self.assertEqual('', repr(lock)) p.join() + self.assertEqual('', repr(rlock)) def test_rlock(self): lock = self.RLock() From 1d7c345e76ef45a73042015469320c0f9aa3430a Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2025 14:34:33 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst diff --git a/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst b/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst new file mode 100644 index 00000000000000..4cf98f105ca88b --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst @@ -0,0 +1 @@ +Fix a flaky test in `test_repr_rlock` about representation of `multiuprocessing.RLock`. From a8014087cbf0bf046c383df54e50b06593d50b50 Mon Sep 17 00:00:00 2001 From: Duprat Date: Mon, 10 Feb 2025 17:46:06 +0100 Subject: [PATCH 4/4] Update news entry file Co-authored-by: Sam Gross --- .../next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst b/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst index 4cf98f105ca88b..7b87d5455c1a70 100644 --- a/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst +++ b/Misc/NEWS.d/next/Tests/2025-02-10-14-34-29.gh-issue-129401.Cq6Ruy.rst @@ -1 +1 @@ -Fix a flaky test in `test_repr_rlock` about representation of `multiuprocessing.RLock`. +Fix a flaky test in ``test_repr_rlock`` that checks the representation of :class:`multiprocessing.RLock`.