Courses/Modern Python

๐Ÿš€ Modern Python

async / await

Concurrent code without threads.

Define a coroutine with async def. Use await to pause for another coroutine. In Pyodide the event loop is already running, so you can await at the top level instead of calling asyncio.run().

import asyncio

async def hello():
    await asyncio.sleep(0)
    return "done"

print(await hello())
main.py
Output
Press Run to execute.
Expected output
[2, 4, 6]

Sign in to track your progress across lessons.