Currently consuming items from a queue is very complex. You need to
use an infinite while loop
call queue.task_done() after processing each item
add all worker tasks to a list
join the queue
cancel all worker tasks.
wait until all worker tasks are cancelled
By adding asyncio.Queue.iter() and asyncio.Queue.iter_nowait(), this becomes a lot easier, you only need to call queue.shutdown(). The same applies to synchronous queues.
Activity
nineteendo commented on Jun 23, 2024
This is an alternative to #120499 and #119154.
Merge pull request #16 from nineteendo/add-asyncio.Queue.iter
vstinner commented on Jun 24, 2024
Please open a single issue to discuss multiple alternatives. I suggest to close this issue.