[Python-ideas] Add closing and iteration to threading.Queue

Cameron Simpson cs at cskk.id.au
Sun Oct 21 23:21:46 EDT 2018


On 21Oct2018 21:19, Vladimir Filipović <hemflit at gmail.com> wrote:
>On Sun, Oct 21, 2018 at 8:45 PM MRAB <python at mrabarnett.plus.com> wrote:
>> FTR, this has been discussed before:
>> [Python-ideas] `__iter__` for queues?
>> https://mail.python.org/pipermail/python-ideas/2010-January/006711.html
>
>Thank you!

Hmm, yes. My post there is this one:

  https://mail.python.org/pipermail/python-ideas/2010-January/006716.html

I want to point out that in my code the single consumer of a Queue is 
incredibly common, so common that I can't off the top of my head think 
of _any_ uses of Queue directly: I _always_ make an IterableQueue and 
simply have the consumer iterate over the iterable queue.

This is _exactly_ like Vladimir's proposal to my mind: my IterableQueue 
is iterable, and has a .close method just like his (prevent further puts 
and indicates end of stream) mediated with a sentinel internally.  
Arbitrary number of putters, _usually_ only one getter but of course 
there's no need for that.

So to my mind his proposal is very simple and sensible, and matches 
almost universally my own use of Queues.

Cheers,
Cameron Simpson <cs at cskk.id.au>


More information about the Python-ideas mailing list