8000 Update locks.py · python/cpython@0384561 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0384561

Browse files
committed
Update locks.py
first feedbacks from Emmanuel Arias
1 parent 6106f21 commit 0384561

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Lib/asyncio/locks.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Synchronization primitives."""
22

3-
__all__ = ('Lock', 'Event', 'Condition', 'Semaphore', 'BoundedSemaphore', 'Barrier', 'BrokenBarrierError')
3+
__all__ = ('Lock', 'Event', 'Condition', 'Semaphore',
4+
'BoundedSemaphore', 'Barrier', 'BrokenBarrierError')
45

56
import collections
67

@@ -431,9 +432,10 @@ def release(self):
431432
# since the previous cycle. In addition, a 'resetting' state exists which is
432433
# similar to 'draining' except that tasks leave with a BrokenBarrierError,
433434
# and a 'broken' state in which all tasks get the exception.
434-
435+
#
436+
# Asyncio equivalent to threading.Barrier
435437
class Barrier(mixins._LoopBoundMixin):
436-
"""Asynchronous equivalent to threading.Barrier
438+
"""Asyncio equivalent to threading.Barrier
437439
438440
Implements a Barrier.
439441
Useful for synchronizing a fixed number of tasks at known synchronization
@@ -495,10 +497,9 @@ async def _block (self):
495497
# It is draining or resetting, wait until done
496498
await self._blocking.wait()
497499

498-
#see if the barrier is in a broken state
500+
# see if the barrier is in a broken state
499501
if self._state < 0:
500502
raise BrokenBarrierError
501-
assert self._state == 0, repr(self)
502503

503504
# Optionally run the 'action' and release the tasks waiting
504505
# in the barrier.
@@ -512,9 +513,7 @@ def _release(self):
512513
self._waiting.set()
513514
except:
514515
#an exception during the _action handler. Break and reraise
515-
self._state = -2
516-
self._blocking.clear()
517-
self._waiting.set()
516+
self.abort()
518517
raise
519518

520519
# Wait in the barrier until we are released. Raise an exception
@@ -524,7 +523,6 @@ async def _wait(self):
524523
# no timeout so
525524
if self._state < 0: # resetting or broken
526525
raise BrokenBarrierError
527-
assert self._state == 1, repr(self)
528526

529527
# If we are the last tasks to exit the barrier, signal any tasks
530528
# waiting for the barrier to drain.

0 commit comments

Comments
 (0)
0