Move it off the event loop. Wrap the blocking call in asyncio.to_thread, or use run_in_executor with a thread pool, so the loop stays free to serve other requests. If the work is CPU bound, send it to a process pool or a background worker such as Celery instead. Left inline, one slow call stalls every other request on that worker.
Why interviewers ask this
Blocking the loop is the defining async mistake, and it produces the worst kind of outage: latency that looks fine under test and collapses under load. The interviewer wants proof you understand cooperative scheduling, that nothing preempts a coroutine, and that you know FastAPI runs plain def endpoints in a threadpool already, which is often the simplest correct answer.
How to structure your answer
- Explain why blocking the loop is fatal.
- Offer to_thread or an executor for I/O.
- Route CPU bound work to processes or a queue.
- Mention the plain def endpoint option in FastAPI.
Example answer
The reason it matters is that asyncio is cooperative and single threaded, so a coroutine keeps the loop until it awaits something. A blocking driver call sitting in an async handler freezes every other in flight request on that worker, and under low traffic you will never notice. Cheapest fix in FastAPI is to define the endpoint with plain def rather than async def, and the framework runs it in its threadpool for you. If I need it inside an async function, asyncio.to_thread wraps the call and awaits the result. Where I am careful is the thread pool size, because the default is small and a slow dependency will queue behind it, so I size it against the concurrency I expect and add a timeout. For anything CPU heavy, threads do not help under the default build, so it goes to a process pool or out to a Celery worker. We caught one of these with a legacy SOAP client that took eight seconds, and p99 latency across an entire service was tracking that one call.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How would you detect a blocked loop in production?
- What does asyncio debug mode report?
- Is a synchronous database driver ever acceptable there?
Related python developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions