@@ -439,16 +439,19 @@ def acquire(self, blocking=True, timeout=None):
439439
440440 __enter__ = acquire
441441
442- def release (self ):
443- """Release a semaphore, incrementing the internal counter by one.
442+ def release (self , n = 1 ):
443+ """Release a semaphore, incrementing the internal counter by one or more .
444444
445445 When the counter is zero on entry and another thread is waiting for it
446446 to become larger than zero again, wake up that thread.
447447
448448 """
449+ if n < 1 :
450+ raise ValueError ('n must be one or more' )
449451 with self ._cond :
450- self ._value += 1
451- self ._cond .notify ()
452+ self ._value += n
453+ for i in range (n ):
454+ self ._cond .notify ()
452455
453456 def __exit__ (self , t , v , tb ):
454457 self .release ()
@@ -475,8 +478,8 @@ def __init__(self, value=1):
475478 Semaphore .__init__ (self , value )
476479 self ._initial_value = value
477480
478- def release (self ):
479- """Release a semaphore, incrementing the internal counter by one.
481+ def release (self , n = 1 ):
482+ """Release a semaphore, incrementing the internal counter by one or more .
480483
481484 When the counter is zero on entry and another thread is waiting for it
482485 to become larger than zero again, wake up that thread.
@@ -485,11 +488,14 @@ def release(self):
485488 raise a ValueError.
486489
487490 """
491+ if n < 1 :
492+ raise ValueError ('n must be one or more' )
488493 with self ._cond :
489- if self ._value >= self ._initial_value :
494+ if self ._value + n > self ._initial_value :
490495 raise ValueError ("Semaphore released too many times" )
491- self ._value += 1
492- self ._cond .notify ()
496+ self ._value += n
497+ for i in range (n ):
498+ self ._cond .notify ()
493499
494500
495501class Event :
0 commit comments