1
1
"""Synchronization primitives."""
2
2
3
- __all__ = ('Lock' , 'Event' , 'Condition' , 'Semaphore' , 'BoundedSemaphore' , 'Barrier' , 'BrokenBarrierError' )
3
+ __all__ = ('Lock' , 'Event' , 'Condition' , 'Semaphore' ,
4
+ 'BoundedSemaphore' , 'Barrier' , 'BrokenBarrierError' )
4
5
5
6
import collections
6
7
@@ -431,9 +432,10 @@ def release(self):
431
432
# since the previous cycle. In addition, a 'resetting' state exists which is
432
433
# similar to 'draining' except that tasks leave with a BrokenBarrierError,
433
434
# and a 'broken' state in which all tasks get the exception.
434
-
435
+ #
436
+ # Asyncio equivalent to threading.Barrier
435
437
class Barrier (mixins ._LoopBoundMixin ):
436
- """Asynchronous equivalent to threading.Barrier
438
+ """Asyncio equivalent to threading.Barrier
437
439
438
440
Implements a Barrier.
439
441
Useful for synchronizing a fixed number of tasks at known synchronization
@@ -495,10 +497,9 @@ async def _block (self):
495
497
# It is draining or resetting, wait until done
496
498
await self ._blocking .wait ()
497
499
498
- #see if the barrier is in a broken state
500
+ # see if the barrier is in a broken state
499
501
if self ._state < 0 :
500
502
raise BrokenBarrierError
501
- assert self ._state == 0 , repr (self )
502
503
503
504
# Optionally run the 'action' and release the tasks waiting
504
505
# in the barrier.
@@ -512,9 +513,7 @@ def _release(self):
512
513
self ._waiting .set ()
513
514
except :
514
515
#an exception during the _action handler. Break and reraise
515
- self ._state = - 2
516
- self ._blocking .clear ()
517
- self ._waiting .set ()
516
+ self .abort ()
518
517
raise
519
518
520
519
# Wait in the barrier until we are released. Raise an exception
@@ -524,7 +523,6 @@ async def _wait(self):
524
523
# no timeout so
525
524
if self ._state < 0 : # resetting or broken
526
525
raise BrokenBarrierError
527
- assert self ._state == 1 , repr (self )
528
526
529
527
# If we are the last tasks to exit the barrier, signal any tasks
530
528
# waiting for the barrier to drain.
0 commit comments