https://github.com/python/cpython/commit/ca2275025bf25427758bc5d7adecc0455068f1e9
commit: ca2275025bf25427758bc5d7adecc0455068f1e9
branch: 3.12
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-07-30T09:12:11Z
summary:

[3.12] gh-121474: Add threading.Barrier parties arg sanity check. (GH-121480) 
(GH-122443)

(cherry picked from commit d27a53fc02a87e76066fc4e15ff1fff3922a482d)

Co-authored-by: Clinton <[email protected]>

files:
A Misc/NEWS.d/next/Library/2024-07-08-03-45-34.gh-issue-121474.NsvrUN.rst
M Lib/test/lock_tests.py
M Lib/threading.py

diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index 024c6debcd4a54..8c8f8901f00178 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -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
diff --git a/Lib/threading.py b/Lib/threading.py
index 7cb291d9955a3c..0bba85d08a0151 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -685,6 +685,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
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 00000000000000..605f30d76f5d47
--- /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).

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to