Re: use of Queue

2008-08-27 Thread Raymond Hettinger
On Aug 27, 4:55 pm, Paul Rubin wrote: > [EMAIL PROTECTED] writes: > > Or make the consumers daemon threads so that when the producers are finished > > an all non-daemon threads exit, the consumers do as well. > > How are the consumers supposed to know when the producers a

Re: use of Queue

2008-08-27 Thread Paul Rubin
[EMAIL PROTECTED] writes: > Or make the consumers daemon threads so that when the producers are finished > an all non-daemon threads exit, the consumers do as well. How are the consumers supposed to know when the producers are finished? Yes, there are different approaches like sentinels, but the

Re: use of Queue

2008-08-27 Thread Fredrik Lundh
Alexandru Mosoi wrote: how is Queue intended to be used? I found the following code in python manual, but I don't understand how to stop consumers after all items have been produced. I tried different approaches but all of them seemed incorrect (race, deadlock or duplicating queue functionality)

Re: use of Queue

2008-08-27 Thread Iain King
On Aug 27, 1:17 pm, Alexandru Mosoi <[EMAIL PROTECTED]> wrote: > On Aug 27, 12:45 pm, Alexandru Mosoi <[EMAIL PROTECTED]> wrote: > > > > > how is Queue intended to be used? I found the following code in python > > manual, but I don't understand how to stop consumers after all items > > have been

Re: use of Queue

2008-08-27 Thread Diez B. Roggisch
> > 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 item

Re: use of Queue

2008-08-27 Thread Alexandru Mosoi
On Aug 27, 12:45 pm, Alexandru Mosoi <[EMAIL PROTECTED]> wrote: > how is Queue intended to be used? I found the following code in python > manual, but I don't understand how to stop consumers after all items > have been produced. I tried different approaches but all of them > seemed incorrect (rac

Re: use of Queue

2008-08-27 Thread Alexandru Mosoi
On Aug 27, 2:54 pm, Jeff <[EMAIL PROTECTED]> wrote: > Queue raises an Empty exception when there are no items left in the > queue.  Put the q.get() call in a try block and exit in the except > block. Wrong. What if producer takes a long time to produce an item? Consumers will find the queue empty

Re: use of Queue

2008-08-27 Thread Jeff
> 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 a

Re: use of Queue

2008-08-27 Thread Alexandru Mosoi
On Aug 27, 1:06 pm, Gerhard Häring <[EMAIL PROTECTED]> wrote: > Alexandru Mosoi wrote: > > how is Queue intended to be used? I found the following code in python > > manual, but I don't understand how to stop consumers after all items > > have been produced. I tried different approaches but all of

Re: use of Queue

2008-08-27 Thread skip
skip> Or make the consumers daemon threads so that when the producers skip> are finished an all non-daemon threads exit, the consumers do as skip> well. Forget that I wrote this. If they happen to be working on the token they've consumed at the time the other threads exit, they will

Re: use of Queue

2008-08-27 Thread skip
Diez> Put a sentinel into the queue that gets interpreted as "terminate" Diez> for the workers. You need of course to put it in there once for Diez> each worker. Or make the consumers daemon threads so that when the producers are finished an all non-daemon threads exit, the consumers

Re: use of Queue

2008-08-27 Thread Gerhard Häring
Alexandru Mosoi wrote: how is Queue intended to be used? I found the following code in python manual, but I don't understand how to stop consumers after all items have been produced. I tried different approaches but all of them seemed incorrect (race, deadlock or duplicating queue functionality)

Re: use of Queue

2008-08-27 Thread Diez B. Roggisch
Alexandru Mosoi wrote: > how is Queue intended to be used? I found the following code in python > manual, but I don't understand how to stop consumers after all items > have been produced. I tried different approaches but all of them > seemed incorrect (race, deadlock or duplicating queue functio

use of Queue

2008-08-27 Thread Alexandru Mosoi
how is Queue intended to be used? I found the following code in python manual, but I don't understand how to stop consumers after all items have been produced. I tried different approaches but all of them seemed incorrect (race, deadlock or duplicating queue functionality) def worker():