use of Queue

Diez B. Roggisch deets at nospam.web.de
Wed Aug 27 08:40:40 EDT 2008


> 
> Your solution works assuming that you know how many consumer threads
> you have :). I don't :). More than that, it's not correct if you have
> more than one producer :). Having a sentinel was my very first idea,
> but as you see... it's a race condition (there are cases in which not
> all items are processed).

If you have several producers, how do you coordinate when to shut down?

Apart from that, you can easily solve the problem of not knowing how many
consumers you have by making a consumer stuff back the sentinel into the
queue. Then it will ripple down until no consumer is left.

Diez



More information about the Python-list mailing list