TaskQueue
Carl Banks
invalidemail at aerojockey.com
Tue Mar 21 09:07:49 EST 2006
Rene Pijlman wrote:
> >2) complicating the producer logic to append one sentinel for each consumer
> >when the data stream is done
>
> for i in range(self.numberOfThreads):
> self.workQueue.put(None)
Or, you could just put one sentinel in the Queue, and subclass the
Queue's _get method not to take the sentinel out. It might help keep
bookkeeping down (and it seems Raymond was in a situation where keeping
track of threads wasn't so easy).
BTW, for sentinels, I recommend creating one using:
sentinel = object()
Because, although it's not applicable to your example, sometimes None
is an object you want to pass through. (I think Alex Martelli came up
with that one.)
Carl Banks
More information about the Python-list
mailing list