Feature or enhancement
Proposal:
Currently consuming items from a queue can be a bit more complex than necessary. You need to
- use an infinite while loop
- check for a sentinel or add all worker tasks to a list
- call
q.task_done() after processing each item
- join the queue
- cancel all worker tasks
- wait until all worker tasks are cancelled
By allowing iteration over *.Queue, this becomes a bit easier, you only need to call queue.shutdown().
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
Linked PRs
- Implementation A: add
asyncio.Queue.__aiter__() and queue.Queue.__iter__()
- Implementation B: add
*.Queue.iter() and *.Queue.iter_nowait()
Feature or enhancement
Proposal:
Currently consuming items from a queue can be a bit more complex than necessary. You need to
q.task_done()after processing each itemBy allowing iteration over
*.Queue, this becomes a bit easier, you only need to callqueue.shutdown().Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
asyncio.Queue.__aiter__#119154queue.Queuean iterable #120499*.Queue.iter()and*.Queue.iter_nowait()#120924Linked PRs
asyncio.Queue.__aiter__()andqueue.Queue.__iter__()asyncio.Queuean asynchronous iterable #120491queue.Queuean iterable #120503*.Queue.iter()and*.Queue.iter_nowait()*.Queue.iter()and*.Queue.iter_nowait()#120925