Skip to content

Chapter 5 of 6

Bounded queues and worker pools

Creating a task per item and letting them all queue on a semaphore is correct and produces the right answer, but every coroutine and its payload sits in memory from the first instant and nothing pushes back on whatever is producing the work. Feeding the same 10,000 calls through a bounded queue drained by 16 long-lived workers gives flat memory, real backpressure and results written as they land, at identical wall clock.

Async and concurrency in Python — read the current version at https://daviddominguez.dev/learn/en/async-and-concurrency-in-python/bounded-queues-and-worker-pools

Back to top