Multi thread reading a file
rylesny at gmail.com
Fri Jul 3 05:09:25 CEST 2009
On Jul 2, 10:20 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> ryles <ryle... at gmail.com> writes:
> > >>> # Oh... yeah. I really *did* want 'is None' and not '== None'
> > >>> which iter() will do. Sorry guys!
> > Please don't let this happen to you too ;)
> None is a perfectly good value to put onto a queue. I prefer
> using a unique sentinel to mark the end of the stream:
> sentinel = object()
I agree, this is cleaner than None. We're still in the same boat,
though, regarding iter(). Either it's 'item == None' or 'item == object
()', and depending on the type, __eq__ can introduce some avoidable
FWIW, even object() has its disadvantages. Namely, it doesn't work for
multiprocessing.Queue which pickles and unpickles, thus giving you a
new object. One way to deal with this is to define a "Stopper" class
and type check objects taken from the queue. This is not news to
anyone who's worked with multiprocessing.Queue, though.
More information about the Python-list