Worker Pools interview problems
A worker pool question asks you to process a stream of jobs with a fixed number of concurrent workers. In asyncio the standard shape is one asyncio.Queue, N tasks running while True: job = await queue.get(), and a shutdown path. That path is either one sentinel per worker or await queue.join() followed by cancelling the workers. Variants ask you to return results in input order, retry failed jobs, resize the pool, or report per-job errors without stopping the pool.
Typical mistakes are letting one job's exception kill its worker so the pool silently shrinks, forgetting queue.task_done() in a finally so join() hangs, sending fewer sentinels than workers, and appending results to a shared list and assuming order. A strong answer catches and records per-job failures inside the worker loop and keeps results in a dict keyed by job index or in pre-sized slots. It shuts down without losing queued work and explains the difference between a pool (fixed workers pulling jobs) and a semaphore (one task per job, capped in flight). It also says when each fits.
1 open problem
- 12Inference Worker Poolmedium
Run inference requests through a fixed pool of asyncio workers sharing one queue, isolate failures, and return results in input order.
3 locked
These open in order of demand. Open one and press I want this one to ask for it.
- 19Bounded Worker Pool with Graceful Shutdown Lockedhard
Build an asyncio worker pool with a bounded job queue, backpressure on submit, and a graceful shutdown that drains accepted jobs and rejects new ones.
- 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.
- 26Async Priority Job Scheduler Lockedhard
Run submitted async jobs on N workers in priority order, FIFO within a priority, with cancellation and a draining shutdown.