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

asyncio.Condition

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


Import

import asyncio
from asyncio import Condition

Signature & Overview

asyncio.Condition(lock=None)

Asynchronous equivalent to threading.Condition.

Methods & Attributes

Usage

import asyncio

async def main():
    cond = asyncio.Condition()
    ready = False
    async def setter():
        nonlocal ready
        async with cond:
            ready = True
            cond.notify_all()
    t = asyncio.create_task(setter())
    async with cond:
        await cond.wait_for(lambda: ready)
    await t
    assert ready is True

asyncio.run(main())

Gotchas

REPL Inspect

from asyncio import Condition
help(Condition)

Linked from

Related notes