]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-121474: Add threading.Barrier parties arg sanity check. (GH-121480)
authorClinton <pygeek@users.noreply.github.com>
Tue, 30 Jul 2024 08:53:07 +0000 (04:53 -0400)
committerGitHub <noreply@github.com>
Tue, 30 Jul 2024 08:53:07 +0000 (11:53 +0300)
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 2dcdd0c9e067b6e2800a5a2d41a777ad01aeeb42..94ea2f081783696ed03928a085c27bee6a46cdca 100644 (file)
@@ -689,6 +689,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).