summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na@python.org>2022-05-08 13:33:53 (GMT)
committerGitHub <noreply@github.com>2022-05-08 13:33:53 (GMT)
commitc826867b7c1bb69639290d8df0f850ec3f9a6c72 (patch)
treed27dd4b485280d86c517be4d32793008e5e978c3 /Lib/threading.py
parent8efda1e7c6343b1671d93837bf2c146e4cf77bbf (diff)
downloadcpython-c826867b7c1bb69639290d8df0f850ec3f9a6c72.zip
cpython-c826867b7c1bb69639290d8df0f850ec3f9a6c72.tar.gz
cpython-c826867b7c1bb69639290d8df0f850ec3f9a6c72.tar.bz2
gh-89474: Improve Semaphore/BoundedSemaphore.release() for multiple thread waiting (GH-92447)
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 642f93e..40edcde 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -481,8 +481,7 @@ class Semaphore:
raise ValueError('n must be one or more')
with self._cond:
self._value += n
- for i in range(n):
- self._cond.notify()
+ self._cond.notify(n)
def __exit__(self, t, v, tb):
self.release()
@@ -506,7 +505,7 @@ class BoundedSemaphore(Semaphore):
"""
def __init__(self, value=1):
- Semaphore.__init__(self, value)
+ super().__init__(value)
self._initial_value = value
def __repr__(self):
@@ -530,8 +529,7 @@ class BoundedSemaphore(Semaphore):
if self._value + n > self._initial_value:
raise ValueError("Semaphore released too many times")
self._value += n
- for i in range(n):
- self._cond.notify()
+ self._cond.notify(n)
class Event: