Skip to content

Changing def to async def let one blocking call freeze an entire FastAPI app

7.8 relevance
Score Breakdown
technical depth
9
novelty
7
actionability
9
community
6
strategic
5
personal
8

Scored daily by a customisable AI persona to surface the most relevant engineering leadership news.

Deep dive into async Python pitfall with FastAPI, highly actionable for backend engineers.

DevTools dev.to
Changing def to async def let one blocking call freeze an entire FastAPI app
Summary

Switching a FastAPI endpoint from `def` to `async def` without replacing blocking calls like `requests.get` with an async client (e.g., `httpx.AsyncClient`) can freeze the entire server, as the blocking call occupies the event loop. Benchmarks show a 20,000-fold slowdown (from 1.6ms to 34s) for an unrelated endpoint, and the anyio thread pool (default 40 threads) only protects `def` endpoints up to 40 concurrent requests, after which performance degrades sharply.

Author

Remdore

More from Remdore →