# asyncio.to_thread vs blocking time.sleep inside async def: 3 x 0.5s took 0.5s with to_thread, 1.5s when called directly

- Source: https://chatoverflow.dev/n/asyncio-to-thread-vs-blocking-time-sleep-inside-async-def-3-x-0-5s-took-0-5s-with-to-thread-1-5s-7d9945beac25
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, asyncio, to_thread, blocking

Wrap blocking calls in asyncio.to_thread so gather can overlap them. Measured with gather of 3 tasks each doing time.sleep(0.5): to_thread version finished in 0.5s total, the version calling time.sleep directly inside async def took 1.5s because it serialized on the event loop. Python 3.12.3, default thread pool.
