@@ -452,7 +452,7 @@ def __init__(self, parties, action=None, *, loop=mixins._marker):
452
452
raise ValueError ('parties must be > 0' )
453
453
454
454
self ._waiting = Event () # used notify all waiting tasks
455
- self ._blocking = Event () # used block tasks while wainting tasks are draining or broken
455
+ self ._blocking = Event () # used block new tasks while waiting tasks are draining or broken
456
456
self ._action = action
457
457
self ._parties = parties
458
458
self ._state = 0 # 0 filling, 1, draining, -1 resetting, -2 broken
@@ -491,7 +491,7 @@ async def wait(self):
491
491
# Block until the barrier is ready for us, or raise an exception
492
492
# if it is broken.
493
493
async def _block (self ):
494
- if self ._state in (- 1 , 1 ):
494
+ while self ._state in (- 1 , 1 ):
495
495
# It is draining or resetting, wait until done
496
496
await self ._blocking .wait ()
497
497
@@ -522,17 +522,17 @@ def _release(self):
522
522
async def _wait (self ):
523
523
await self ._waiting .wait ()
524
524
# no timeout so
525
- if self ._state < 0 :
525
+ if self ._state < 0 : # resetting or broken
526
526
raise BrokenBarrierError
527
527
assert self ._state == 1 , repr (self )
528
528
529
529
# If we are the last tasks to exit the barrier, signal any tasks
530
530
# waiting for the barrier to drain.
531
531
def _exit (self ):
532
532
if self ._count == 0 :
533
- if self ._state == 1 :
533
+ if self ._state == 1 : # draining
534
534
self ._state = 0
535
- elif self ._state == - 1 :
535
+ elif self ._state == - 1 : # resetting
536
536
self ._state = 0
537
537
self ._waiting .clear ()
538
538
self ._blocking .set ()
@@ -544,12 +544,12 @@ def reset(self):
544
544
raised.
545
545
"""
546
546
if self ._count > 0 :
547
- if self ._state in (0 , 1 ):
548
- #reset the barrier, waking up tasks
547
+ if self ._state in (0 , 1 ): # filling or draining
548
+ # reset the barrier, waking up tasks
549
549
self ._state = - 1
550
550
elif self ._state == - 2 :
551
- #was broken, set it to reset state
552
- #which clears when the last tasks exits
551
+ # was broken, set it to reset state
552
+ # which clears when the last tasks exits
553
553
self ._state = - 1
554
554
self ._waiting .set ()
555
555
self ._blocking .clear ()
0 commit comments