import asyncio
async def wait_briefly():
await asyncio.sleep(1)
print("Finished")Line-by-line explanation
- Asyncio provides asynchronous tools.
async defdefines a coroutine.awaitpauses this task without blocking all async work.- After one second, Finished is displayed.
asyncio.run(wait_briefly())Line-by-line explanation
- The coroutine is created by calling it.
asyncio.runmanages the asynchronous event loop.- The program runs until the coroutine finishes.