]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-121474: Add threading.Barrier parties arg sanity check. (GH-121480) (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 30 Jul 2024 09:12:11 +0000 (11:12 +0200)
committerGitHub <noreply@github.com>
Tue, 30 Jul 2024 09:12:11 +0000 (09:12 +0000)
(cherry picked from commit d27a53fc02a87e76066fc4e15ff1fff3922a482d)

Co-authored-by: Clinton <pygeek@users.noreply.github.com>
Lib/test/lock_tests.py
Lib/threading.py
Misc/NEWS.d/next/Library/2024-07-08-03-45-34.gh-issue-121474.NsvrUN.rst [new file with mode: 0644]

index 024c6debcd4a5472444b050ebc166334381d6fd7..8c8f8901f00178b121c01e8212296f3a039a8b6b 100644 (file)
@@ -1013,6 +1013,10 @@ class BarrierTests(BaseTestCase):
         self.assertEqual(self.barrier.n_waiting, 0)
         self.assertFalse(self.barrier.broken)
 
+    def test_constructor(self):
+        self.assertRaises(ValueError, self.barriertype, parties=0)
+        self.assertRaises(ValueError, self.barriertype, parties=-1)
+
     def test_barrier(self, passes=1):
         """
         Test that a barrier is passed in lockstep
index 7cb291d9955a3c7b747ba4a45e95fdc4151a50ce..0bba85d08a015124d86de4e15ba054605daf7342 100644 (file)
@@ -685,6 +685,8 @@ class Barrier:
         default for all subsequent 'wait()' calls.
 
         """
+        if parties < 1:
+            raise ValueError("parties must be > 0")
         self._cond = Condition(Lock())
         self._action = action
         self._timeout = timeout
diff --git a/Misc/NEWS.d/next/Library/2024-07-08-03-45-34.gh-issue-121474.NsvrUN.rst b/Misc/NEWS.d/next/Library/2024-07-08-03-45-34.gh-issue-121474.NsvrUN.rst
new file mode 100644 (file)
index 0000000..605f30d
--- /dev/null
@@ -0,0 +1,2 @@
+Fix missing sanity check for ``parties`` arg in :class:`threading.Barrier`
+constructor. Patch by Clinton Christian (pygeek).