@@ -492,15 +492,15 @@ async def _block(self):
492
492
# It is draining or resetting, wait until done
493
493
# unless a CancelledError occurs
494
494
try :
495
- await self ._cond .wait_for (lambda : not (self ._is_draining () or
496
- self ._is_resetting ()))
495
+ await self ._cond .wait_for (lambda : not (self ._draining () or
496
+ self ._resetting ()))
497
497
except exceptions .CancelledError :
498
498
self ._count_block -= 1
499
499
raise
500
500
self ._count_block -= 1
501
501
502
502
# see if the barrier is in a broken state
503
- if self ._is_broken () :
503
+ if self .broken :
504
504
raise BrokenBarrierError
505
505
506
506
# Optionally run the 'action' and release the tasks waiting
@@ -528,17 +528,17 @@ async def _wait(self):
528
528
"""
529
529
# wait for end of filling
530
530
# unless a CancelledError occurs
531
- await self ._cond .wait_for (lambda : not self ._is_filling ())
531
+ await self ._cond .wait_for (lambda : not self ._filling ())
532
532
533
- if self ._is_broken () or self ._is_resetting ():
533
+ if self .
8000
broken or self ._resetting ():
534
534
raise BrokenBarrierError
535
535
536
536
def _exit (self ):
537
537
"""If we are the last tasks to exit the barrier, signal any tasks
538
538
waiting for the barrier to drain.
539
539
"""
540
540
if self ._count == 0 :
541
- if self ._is_resetting () or self ._is_draining ():
541
+ if self ._resetting () or self ._draining ():
542
542
self ._set_filling ()
543
543
self ._cond .notify_all ()
544
544
@@ -549,8 +549,8 @@ async def reset(self):
549
549
"""
550
550
async with self ._cond :
551
551
if self ._count > 0 :
552
- if not self ._is_resetting ():# self._is_filling ()
553
- # or self._is_draining ()
552
+ if not self ._resetting ():# self._filling ()
553
+ # or self._draining ()
554
554
# or self.is_broken()
555
555
#reset the barrier, waking up tasks
556
556
self ._set_resetting ()
@@ -580,16 +580,26 @@ def parties(self):
580
580
@property
581
581
def n_waiting (self ):
582
582
"""Return the number of tasks currently waiting at the barrier."""
583
- if self ._is_filling ():
583
+ if self ._filling ():
584
584
return self ._count
585
585
return 0
586
586
587
587
@property
588
- def n_blocking (self ):
589
- """Return the number of tasks currently blocking at the barrier."""
590
- if self ._is_draining ():
591
- return self ._count_block
592
- return 0
588
+ def broken (self ):
589
+ """Return True if the barrier is in a broken state."""
590
+ return self ._state == - 2
591
+
592
+ def _draining (self ):
593
+ """Return True if the barrier is draining."""
594
+ return self ._state == 1
595
+
596
+ def _filling (self ):
597
+ """Return True if the barrier is filling."""
598
+ return self ._state == 0
599
+
600
+ def _resetting (self ):
601
+ """Return True if the barrier is resetting."""
602
+ return self ._state == - 1
593
603
594
604
def _set_broken (self ):
595
605
"""Set state to broken."""
@@ -607,22 +617,6 @@ def _set_resetting(self):
607
617
"""Set state to resetting."""
608
618
self ._state = - 1
609
619
610
- def _is_broken (self ):
611
- """Return True if the barrier is in a broken state."""
612
- return self ._state == - 2
613
-
614
- def _is_draining (self ):
615
- """Return True if the barrier is draining."""
616
- return self ._state == 1
617
-
618
- def _is_filling (self ):
619
- """Return True if the barrier is filling."""
620
- return self ._state == 0
621
-
622
- def _is_resetting (self ):
623
- """Return True if the barrier is resetting."""
624
- return self ._state == - 1
625
-
626
620
627
621
# exception raised by the Barrier class
628
622
class BrokenBarrierError (RuntimeError ):
0 commit comments