Code Quiz

Blocking the Event Loop

Spot why this asyncio program runs serially instead of concurrently.

Codepython
import asyncio
import time

async def fetch(name, delay):
    print(f"start {name}")
    time.sleep(delay)   # simulate I/O wait
    print(f"done {name}")
    return name

async def main():
    start = time.perf_counter()
    results = await asyncio.gather(
        fetch("A", 2),
        fetch("B", 2),
        fetch("C", 2),
    )
    print(results, f"in {time.perf_counter() - start:.1f}s")

asyncio.run(main())

The tasks are gathered together but the program still takes ~6 seconds instead of ~2. What is the bug?