Zest.

Python: Async / await basics

A short, tested Python example for async / await basics. Copy it and adjust the names and paths for your project.

Python
import asyncio

async def fetch(n):
    await asyncio.sleep(1)
    return n * 2

async def main():
    results = await asyncio.gather(fetch(1), fetch(2), fetch(3))
    print(results)

asyncio.run(main())

Find it in Zest

Search for “python async / await basics” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Python examples

All Python examples