A single Uvicorn worker runs one event loop. async def endpoints run directly on that loop and handle many requests concurrently while they await I/O; def endpoints are dispatched to a thread pool (AnyIO, with a default limit of about 40 threads) so blocking code does not stall the loop.
Python's global interpreter lock means threads do not speed up CPU-bound Python code, so for real parallelism you use multiple worker processes (or a task queue for heavy jobs).
Concurrency helps I/O-bound services (database, HTTP and LLM calls); it does not make CPU-heavy functions faster.
Loading…