This repository was archived by the owner on Nov 23, 2017. It is now read-only.
Implement __aiter__ protocol on a Queue #445
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Many times when using asycio.Queue a task is created to process the queue continually, resulting in code such as this:
Which feels less than ideal for a few reasons:
Instead in many cases it would feel more pythonic to iterate the results of a queue in a task:
It doesn't substantially change the LOC, but it does, in my opinion, read a little more fluidly.
This does open up a few questions on how, and when, to raise
StopAsyncIteration
:__del__
didn't feel right, while it works with scope - using it manually feels wrong and it obviously kills the queue you may otherwise plan to continue using - among other questions in an async env.join
could be used to synchronize processing before continuing to be used again - and thus cannot be reliably used to suggest the iterator should discontinue consuming._finished
appears to be, and I may be misunderstanding, primarily around whether or not there is data at that moment, not if the queue is fully closed (I picture a case in which a consumer consumes faster than a producer produces)That leaves me with a few options that seem reasonable (with various implementations):
Outstanding questions:
join
should set this value, since a producer could callq.join(); q.put(queues.END_QUEUE)
(basically saying we wouldn't need to make this decision for them)This may not be the best implementation, however I wanted to start a conversation around it as it has, thus far, been nice in a side project and others were encouraging me to. Granted our case is limited and instead I could put this in an external lib.
If you like the method idea instead and have a good name idea - I am at a loss at the moment...