-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-119154: Simplify consumers by making asyncio.Queue
an asynchronous iterable
#120491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: Guido van Rossum <guido@python.org>
asyncio.Queue.__aiter__()
asyncio.Queue.__aiter__()
cc @gvanrossum, @Zac-HD |
I hope sumeone will review this. Right now I am not available as a reviewer, sorry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two bits of idiom noted below, but overall this looks great to me - thanks, @nineteendo!
Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nineteendo, Thanks for the PR. I left a comment on the doc and will take a closer look at the implementation after I hear back about the expected behavior.
Hi @nineteendo @Zac-HD @kumaraditya303 @itamaro @ambv, @carljm, I've noticed a recent trend that the ayncio PR titles and body text are often very terse without much context on what the change is and why. To help reviewers and to give context to future contributors, let's raise the bar a bit on how we document asyncio PRs.
Two sentences (one with purpose: why; one with change: what) would be very helpful for reviewers for both individual and stacked task PRs. It would likely also help us turn around PRs in a more timely manner. Thanks! |
asyncio.Queue.__aiter__()
asyncio.Queue
an asynchronous iterable
I've adjusted the PR title and body text. I hope it's a bit clearer now. The example is based on the current one in the documentation. |
I want to think some more about what would be the best approach to support this for both synchronous and asynchronous queues. |
I finished the alternative pull request: #120925. Decide if you prefer it over the current pull request. |
@nineteendo Please refrain from opening multiple pull requests at one time for the same issue. Instead, iterating on one PR toward a preferred solution. Here is the preferred approach:
Thanks! |
Sorry for the trouble, the original issue technically didn't apply to syncronous queues (as per the title). |
asyncio.Queue
an asynchronous iterableasyncio.Queue
an asynchronous iterable
asyncio.Queue
an asynchronous iterableasyncio.Queue
an asynchronous iterable
Marking this as closed for the reasons listed in #120925 Thanks for the work on this. It was a plausible idea but queues are more versatile than the iterator protocol allows. |
Purpose
Currently consuming items from a queue is very complex. You need to
queue.task_done()
after processing each itemBy making
asyncio.Queue
an asynchronous iterable, this becomes a lot easier, you only need to callqueue.shutdown()
.Overview of changes
asyncio.Queue.__aiter__()
returns an iterator which iterates over the queue of items_AsyncQueueIterator
has been added to handle the iterationExample
Without iteration
With iteration
Output
asyncio.Queue.__aiter__
#119154📚 Documentation preview 📚:
library/asyncio-queue.html