Originally published on Code Beneath .
The asyncio event loop is single-threaded. When you call a blocking function inside an async context, you freeze the entire loop, and all other coroutines starve. The standard solution is to push blocking work to a thread pool using run_in_executor , but many engineers misunderstand when to reach for it, how it actually works, and what performance tradeoffs exist. This article walks through a python asyncio run in executor blocking io example and shows you the internals, the gotchas, and when a pure async solution is genuinely better.
The Problem: Blocking Code in the Event Loop
Asyncio's event loop cannot pause a blocking call. If you call time.sleep(1) or perform a synchronous database query inside a coroutine, the loop itself hangs. Every other coroutine waiting for I/O stalls. Here is what this looks like:
import asyncio import time
async def bad_example (): print ( " Start: " , time . time ()) time .…