Top 3 Asyncio Interview Questions
Browse 3 real-world technical and behavioral interview questions about Asyncio. Review scenarios, edge cases, and architectural best practices.
What does the GIL actually prevent, and how do you decide between threads, processes, and asyncio?
The Python GIL serializes CPython bytecode execution, but threads still help I/O-bound work; choose processes for pure Python CPU work and asyncio for many concurrent waits.
A list endpoint that returns fifty orders issues more than a hundred queries, and rewriting it as an async endpoint made it slower. Explain both.
An N+1 happens when the ORM follows a relation lazily once per row; select_related fixes forward foreign keys with a SQL join, prefetch_related issues one extra query per relation and joins in Python. An async endpoint gets slower when it contains a blocking call, because that stalls the whole event loop.
You run ten coroutines concurrently and one of them raises. What happens to the other nine?
With gather they keep running unsupervised and their failures may surface as an unretrieved-exception warning. A TaskGroup, added in Python 3.11, cancels the siblings, waits for them to finish unwinding, and raises an ExceptionGroup you handle with except*.