-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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
Changes from 32 commits
e9c1a3e
3cd59ee
16fc429
f13ddb3
afd7ad4
214548c
9824b63
6358b8e
316b800
92f3295
a18767d
320691c
f43bdb1
4ca4a93
fffacb2
92d7b16
ce23fce
640d2a8
6c9aa6d
e6a5849
583f642
1b6e781
2d5998a
841d50c
d624bea
0a8a72b
b3199df
d71eb91
23e37f4
3bb4e65
9eff835
8580e98
670611f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,20 @@ class QueueShutDown(Exception): | |
| pass | ||
|
|
||
|
|
||
| class _AsyncQueueIterator: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious why you created a new class here as iterator instead of adding
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From #119154 (comment):
|
||
| def __init__(self, queue): | ||
| self._queue = queue | ||
|
|
||
| def __aiter__(self): | ||
| return self | ||
|
|
||
| async def __anext__(self): | ||
| try: | ||
| return await self._queue.get() | ||
| except QueueShutDown: | ||
| raise StopAsyncIteration | ||
|
|
||
|
|
||
|
nineteendo marked this conversation as resolved.
|
||
| class Queue(mixins._LoopBoundMixin): | ||
| """A queue, useful for coordinating producer and consumer coroutines. | ||
|
|
||
|
|
@@ -76,6 +90,9 @@ def _wakeup_next(self, waiters): | |
| waiter.set_result(None) | ||
| break | ||
|
|
||
| def __aiter__(self): | ||
| return _AsyncQueueIterator(self) | ||
|
|
||
| def __repr__(self): | ||
| return f'<{type(self).__name__} at {id(self):#x} {self._format()}>' | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Make :class:`asyncio.Queue` an :term:`asynchronous iterable`. | ||
| Contributed by Wannes Boeykens. |
Uh oh!
There was an error while loading. Please reload this page.