bpo-37334: Add a cancel method to asyncio Queues#14227
bpo-37334: Add a cancel method to asyncio Queues#14227tecki wants to merge 7 commits intopython:mainfrom
Conversation
|
Do you want to allow calling |
|
While I think it does not make much sense, I do not see a good reason to forbid calling |
|
I think the proposal makes the queues API more error-prone: concurrent @1st1 we need your opinion here. |
Is that so? I am not aware of such a behavior, but if there is one, I'm happy to fix it. Could you give an example? |
What about a consumers or producers doing something like: async def consumer(queue):
while not_done:
job = await queue.get()
result = await do_stuff(job)
async def producer(queue):
while not_done:
job = await make_job()
await queue.put(job)(This is the actual case I had, that led me to wish queues had cancellation, that led me to this issue). In either case, they may not be waiting on the queue itself at the moment |
assert that already enqueued values are still processed after the queue is closed.
|
@jpetkau your case can actually be solved pretty easily by setting your So, I would add this "close is close forever" functionality if there is a general agreement about it, but if not I would rather let it be as it is. This PR has been open for almost two years now, it would be cool if it could be finished... |
|
I propose to close this in favor of a |
When working with queues, it is not uncommon that at some point the producer stops producing data for good, or the consumer stops consuming, for example because a network connection broke down or some user simply closed the session.
In this situation it is very useful to simply cancel all the waiting getters and putters. A simple method can do that, Queue.close.
https://bugs.python.org/issue37334