8000 Tune docs · python/cpython@896e274 · GitHub
[go: up one dir, main page]

Skip to content

Commit 896e274

Browse files
committed
Tune docs
1 parent f89dc5f commit 896e274

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

Doc/library/asyncio-sync.rst

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,19 @@ BoundedSemaphore
345345
Barrier
346346
=======
347347

348-
.. versionadded:: 3.11
348+
.. class:: Barrier(parties, action=None)
349349

350350
A barrier object. Not thread-safe.
351351

352-
A barrier is a simple synchronization primitive that allows to block until a
353-
certain number of tasks are waiting on it.
352+
A barrier is a simple synchronization primitive that allows to block until
353+
*parties* number of tasks are waiting on it.
354354
Tasks can wait on the :meth:`~Barrier.wait` method and would be blocked until
355355
the specified number of tasks end up waiting on :meth:`~Barrier.wait`.
356356
At that point all of the waiting tasks would unblock simultaneously.
357357

358+
:keyword:`async with` can be used as an alternative to awaiting on
359+
:meth:`~Barrier.wait`.
360+
358361
The barrier can be reused any number of times.
359362

360363
.. _asyncio_example_barrier:
@@ -363,7 +366,7 @@ Barrier
363366

364367
async def example_barrier():
365368
# barrier with 3 parties
366-
b = asyncio.Barrier(3, done)
369+
b = asyncio.Barrier(3)
367370

368371
# create 2 new waiting tasks
369372
asyncio.create_task(b.wait())
@@ -372,10 +375,10 @@ Barrier
372375
await asyncio.sleep(0)
373376
print(b)
374377

375-
# Now, current task waits
376-
async with b as pos:
377-
print(b)
378-
print("barrier passed")
378+
# The third .wait() call passes the barrier
379+
awaut b.wait()
380+
print(b)
381+
print("barrier passed")
379382

380383
await asyncio.sleep(0)
381384
print(b)
@@ -384,17 +387,12 @@ Barrier
384387

385388
Result of this example is::
386389

387-
<asyncio.locks.Barrier object at 0x105d70100 [filling, waiters:2/3]>
388-
<asyncio.locks.Barrier object at 0x10146c6a0 [draining, waiters:0/3]>
390+
<asyncio.locks.Barrier object at 0x... [filling, waiters:2/3]>
391+
<asyncio.locks.Barrier object at 0x... [draining, waiters:0/3]>
389392
barrier passed
390-
<asyncio.locks.Barrier object at 0x105d70100 [filling, waiters:0/3]>
393+
<asyncio.locks.Barrier object at 0x... [filling, waiters:0/3]>
391394

392-
The example also demonstrates using ``async with`` as an alternative to awaiting
393-
on ``barrier.wait()``.
394-
395-
.. class:: Barrier(parties, action=None)
396-
397-
Create a barrier object for *parties* number of tasks.
395+
.. versionadded:: 3.11
398396

399397
.. coroutinemethod:: wait()
400398

0 commit comments

Comments
 (0)
0