Martin Teichmann <martin.teichm...@gmail.com> added the comment:

Given the reactions I gather "close" is a better name for the method, so I 
changed it accordingly.

In the current implementation, items that had been put on the queue but not 
processed yet still get processed after the close, and I think this is the 
desired behavior. I added a test such that this won't unexpectedly change in 
the future.

To be precise, the current implementation of the queue does not even put new 
items on the queue if there is already a waiting consumer. The item will 
directly be handed over to said consumer, which may hang around on the event 
loop for a bit longer, but during this time the item is not in the queue. This 
also answers the questions about catching the CancelledError: if there are 
waiting consumers, there is nothing on the queue, so the problem of processing 
leftover items does not exist. The same holds for the task_done.

As for the "why don't I just cancel the task?", well, if you know it. There may 
be many consumer or producer tasks waiting for their turn. Sure, you can keep a 
list of all those tasks. But that's exactly the point of the proposed change: 
the Queue already knows all the waiting tasks, no need to keep another list 
up-to-date!

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37334>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to