Avoid blocking an async route

Take your time, follow the code and check your understanding.

The codeHTTP and validation
@app.get("/slow")
async def slow():
    time.sleep(2)
    return {"ok": True}
Your answer4 min · no timer
What needs fixing?

Show solution and explanation

time.sleep blocks the event-loop thread. An awaited asynchronous operation lets the loop handle other work during the wait.

Use await asyncio.sleep(2) for a non-blocking delay.