summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/lock_tests.py4
-rw-r--r--Lib/threading.py2
-rw-r--r--Misc/NEWS.d/next/Library/2024-07-08-03-45-34.gh-issue-121474.NsvrUN.rst2
3 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index 024c6de..8c8f890 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -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
diff --git a/Lib/threading.py b/Lib/threading.py
index 2dcdd0c..94ea2f0 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -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
index 0000000..605f30d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-07-08-03-45-34.gh-issue-121474.NsvrUN.rst
@@ -0,0 +1,2 @@
+Fix missing sanity check for ``parties`` arg in :class:`threading.Barrier`
+constructor. Patch by Clinton Christian (pygeek).