Skip to content

Commit c826867

Browse files
authored
gh-89474: Improve Semaphore/BoundedSemaphore.release() for multiple thread waiting (GH-92447)
1 parent 8efda1e commit c826867

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Lib/threading.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,7 @@ def release(self, n=1):
481481
raise ValueError('n must be one or more')
482482
with self._cond:
483483
self._value += n
484-
for i in range(n):
485-
self._cond.notify()
484+
self._cond.notify(n)
486485

487486
def __exit__(self, t, v, tb):
488487
self.release()
@@ -506,7 +505,7 @@ class BoundedSemaphore(Semaphore):
506505
"""
507506

508507
def __init__(self, value=1):
509-
Semaphore.__init__(self, value)
508+
super().__init__(value)
510509
self._initial_value = value
511510

512511
def __repr__(self):
@@ -530,8 +529,7 @@ def release(self, n=1):
530529
if self._value + n > self._initial_value:
531530
raise ValueError("Semaphore released too many times")
532531
self._value += n
533-
for i in range(n):
534-
self._cond.notify()
532+
self._cond.notify(n)
535533

536534

537535
class Event:

0 commit comments

Comments
 (0)