[Python-ideas] `__iter__` for queues?

Raymond Hettinger raymond.hettinger at gmail.com
Wed Jan 20 23:48:13 CET 2010

On Jan 20, 2010, at 12:28 PM, cool-RR wrote:

> Thanks for the code Raymond. However, what I use is actually simpler:
> def iterate(queue, block=False):
>     '''Iterate over the items in the queue.'''
>     while True:
>         try:
>             yield queue.get(block=block)
>         except Queue.Empty:
>             raise StopIteration

Then it sounds like the existing API is more than adequate for your needs.
Dump the above fragment in your utils module and be done with it.


More information about the Python-ideas mailing list