On this page
  1. asyncio.gather
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

asyncio.gather

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


Import

import asyncio
from asyncio import gather

Signature & Overview

asyncio.gather(*coros_or_futures, return_exceptions=False)

Return a future aggregating results from the given coroutines/futures.

Usage

import asyncio

async def sq(n: int) -> int:
    await asyncio.sleep(0)
    return n * n

async def main():
    res = await asyncio.gather(sq(2), sq(3), sq(4))
    assert res == [4, 9, 16]

asyncio.run(main())

Gotchas

REPL Inspect

from asyncio import gather
help(gather)

Linked from

Related notes