On this page
  1. asyncio.Barrier
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

asyncio.Barrier

Prev: asyncio.as_completed | Up: asyncio | Next: asyncio.BaseEventLoop
Rel: asyncio.AbstractEventLoop, asyncio.AbstractServer, asyncio.all_tasks, asyncio.as_completed
Ref: docs.python.org — asyncio.Barrier
Tags: #public #python3 #stdlib #asyncio


Import

import asyncio
from asyncio import Barrier

Signature & Overview

asyncio.Barrier(parties)

Asyncio equivalent to threading.Barrier Implements a Barrier primitive.

Methods & Attributes

Usage

import asyncio

async def main():
    barrier = asyncio.Barrier(2)
    async def worker():
        await barrier.wait()
        return "done"
    res = await asyncio.gather(worker(), worker())
    assert res == ["done", "done"]

asyncio.run(main())

Gotchas

REPL Inspect

from asyncio import Barrier
help(Barrier)

Linked from

Related notes