Interview Prep/Python for DevOps/Concurrency: threads, processes & asyncio

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.

All Python for DevOps questions Roadmap: Python for automation

More on Concurrency: threads, processes & asyncio