Timeouts interview problems
Timeout questions check that you can bound how long an operation takes and leave the system in a sane state when it runs over. In asyncio you have asyncio.wait_for(coro, timeout) and, since Python 3.11, the async with asyncio.timeout(seconds): context manager, which can cover several awaits at once and be rescheduled. Both cancel the inner work and raise TimeoutError (an alias of asyncio.TimeoutError since 3.11). asyncio.wait(tasks, timeout=...) is different. It returns (done, pending) and cancels nothing.
Interviewers see the same mistakes often. Candidates apply a fresh timeout to every retry so the total wait is attempts times timeout, forget that the timed-out task still holds a connection or lock until its finally runs, and catch TimeoutError so broadly that a real bug is reported as a timeout. A strong answer thinks in deadlines, computing deadline = loop.time() + budget once and passing the remaining time down. It also cleans up in finally, and can explain what happens to a coroutine when the timeout fires. It receives CancelledError at its current await.
2 open problems
- 20Dynamic Request Batcherhard
Group concurrent inference requests into batches that flush when full or when the oldest request has waited long enough, with cancellation and drain.
- 25Async Request Deduplicatorhard
Collapse concurrent fetches for the same key into one shared call, with per-caller timeouts that never cancel the shared work.
4 locked
These open in order of demand. Open one and press I want this one to ask for it.
- 10Async Inference with Retries and Timeouts Lockedhard
Run async inference calls under a concurrency cap with a per-attempt timeout, bounded retries, attempt counts and correct cancellation.
- 23Async Worker Pool with Timeouts Lockedmedium
Cap how many async jobs run at once and time out each job from when it starts, not from when it was queued.
- 27Async Inference Batcher Lockedhard
Group single inference requests into batches by size or wait time, with per-request timeouts, cancellation and a draining shutdown.
- 45Stream Idle and Total Timeout Lockedmedium
Wrap an async token stream so it fails when the gap between items is too long or the whole stream runs past a deadline, closing the source.