Explain the asyncio event loop and cooperative multitasking

Tests if you view the event loop as a single-threaded orchestrator, not magic parallelism. Strong answers note it runs tasks and callbacks, manages a ready queue, and yields control at await. Red flag: calling it multithreading or parallel execution.
What's really being asked
The interviewer wants to know if you understand that asyncio concurrency is cooperative and single-threaded. They are checking whether you can separate the event loop's orchestration role from OS preemption or parallelism, and whether you know where control handoffs actually happen. Specifically, they care if you realize that the loop is not executing code simultaneously but rather juggling suspended execution contexts.
The full answer
First, define the event loop as the core runtime that schedules and runs asynchronous tasks and callbacks. Second, list its primary responsibilities: maintaining a queue of ready tasks, executing callbacks via call_soon and call_later, and polling the OS selector for I/O readiness. Third, explain cooperative multitasking: coroutines run until they hit an await expression, at which point they yield control back to the loop by returning a Future or Task to the scheduler. The loop then picks the next ready task from the queue. Fourth, emphasize that this is not parallelism; only one coroutine runs at a time per thread, and context switches happen only at await boundaries, not by force. Fifth, mention that application code usually interacts with the loop indirectly through asyncio.run() or high-level APIs, but the loop object itself is what drives execution.
The mistakes people make
Calling the event loop multithreading or saying it runs coroutines in parallel. Claiming that await creates a new thread. Describing it as preemptive time-slicing like an OS scheduler. Saying the loop is just a while True without mentioning the selector, callback queue, or Task scheduling. Confusing the high-level asyncio.run() abstraction with the low-level loop mechanics. Asserting that coroutines run in the background automatically without being scheduled as Tasks.
What usually comes next
How does the loop handle blocking calls? What is the difference between a coroutine and a Task? How would you run an event loop in a secondary thread? What happens if a coroutine never awaits? How does the ProactorEventLoop differ from SelectorEventLoop on Windows? Why might you call loop.create_future() instead of asyncio.Future() directly?
A concrete example
Imagine a FastAPI endpoint that awaits two database queries. When the first query awaits the network I/O, the coroutine suspends and the event loop schedules the second query's coroutine. While both queries are in flight, the loop polls the OS selector. As soon as the first query's socket reports readiness, the loop resumes that coroutine. No thread per request is needed because the loop interleaves them cooperatively, keeping CPU and memory overhead low.
Interview question
In a single-threaded asyncio program, how does the event loop switch execution from one Task to another?
- a.The running Task must reach an await expression to yield control back to the loopCorrect
- b.The loop polls the OS selector and forcibly interrupts the running Task when other I/O is ready
- c.The loop assigns a small time slice to each Task and preempts it when the slice expires
- d.Tasks automatically run in the background and the loop collects their results when they finish
Why? this is the answer
Asyncio uses cooperative multitasking, so a Task only yields control at an await boundary. Option B is tempting because the loop does poll the OS selector, but it cannot forcibly interrupt a running Task—control must be yielded voluntarily.
Just read this? Test yourself on what you have been reading.
Read the original → docs.python.org
- #asyncio
- #event-loop
- #python
- #concurrency
- #coroutines
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on asyncio — each one lists the topics its interview covers.
See open roles