What happens if you call a blocking function inside a coroutine?
AdvancedConceptConcurrency: threads, processes & asyncio
Answer
It blocks the entire event loop: every other coroutine freezes until it returns. time.sleep(5), requests.get, boto3 calls and heavy CPU work all do this. Fixes: use the async equivalent (await asyncio.sleep, httpx/aiohttp, aioboto3), or offload with await asyncio.to_thread(blocking_fn, arg) (or loop.run_in_executor). Enable debug mode (PYTHONASYNCIODEBUG=1 or asyncio.run(main(), debug=True)) to log callbacks that take longer than 100 ms.
More on Concurrency: threads, processes & asyncio
What is the GIL, and what does it mean for DevOps scripts?IntermediateHow do you use `ThreadPoolExecutor` for parallel API calls?BeginnerThreads vs processes vs asyncio: how do you choose?IntermediateWhat is a race condition, and how do you prevent one in threaded code?IntermediateHow does a producer/consumer pattern with `queue.Queue` work?AdvancedWhat are coroutines, `async def` and `await`?Intermediate