Why are "broken iterators" broken?
fredrik at pythonware.com
Sun Sep 21 18:36:20 CEST 2008
Roy Smith wrote:
> There are plausible examples of collections which grow while you're
> iterating over them. I'm thinking specifically of a queue in a
> multi-threaded application. One thread pushes work onto the back of the
> queue while another pops from the front. The queue could certainly go
> empty at times. But, maybe a Python iterator is just the wrong way to
> model such behavior.
you probably want the consumer thread to block when it catches up with
the producer, rather than exit.
(that's the default behaviour of Python's Queue object, btw)
More information about the Python-list