⚡ Concurrency & Parallelism
Concurrent asyncio
asyncio.gather runs coroutines side by side.
asyncio.gather schedules many coroutines and waits for all of them. Each await is a chance for the event loop to switch.
import asyncio
async def task(name, delay):
await asyncio.sleep(delay)
return name
async def main():
return await asyncio.gather(task("a", 0), task("b", 0), task("c", 0))
print(await main())