Skip to content

gh-121474: Add threading.Barrier parties arg sanity check. #121480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/lock_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@ def multipass(self, results, n):
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
Expand Down
2 changes: 2 additions & 0 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ def __init__(self, parties, action=None, timeout=None):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix missing sanity check for ``parties`` arg in :class:`threading.Barrier`
constructor. Patch by Clinton Christian (pygeek).
Loading