What happens if you call a blocking function inside an async function?hard

Type
conceptual
Topic
async Python
Frequency
common
Tags
async, event loop, blocking, performance
Answer

It blocks the entire event loop — every other coroutine stalls for the duration.

Explanation

The event loop is single-threaded. A blocking call like time.sleep(5), a synchronous DB driver, or heavy CPU work inside async def holds the thread and prevents any other coroutine from running. Fix: use the async equivalent (await asyncio.sleep(5)), or offload to a thread with await asyncio.to_thread(blocking_fn) (Python 3.9+) for IO-bound work, or use loop.run_in_executor(ProcessPoolExecutor()) for CPU-bound work.

Follow-upWhen would you use run_in_executor with a ProcessPoolExecutor vs a ThreadPoolExecutor?