why the method get() of python Queue is hang on there?

Eric Brunel eric_brunel at despammed.com
Mon Aug 14 11:31:15 EDT 2006


On Mon, 14 Aug 2006 17:10:13 +0200, zxo102 <zxo102 at gmail.com> wrote:

> Hi,
>    I am using Queue from python2.4. Here is what happen to me:
>
> import Queue
> b = Queue.Queue(0)
> b.put(9999)
> b.get()   # this is ok, it pops out 9999
> b.get()   # this one does not return anything and is hang on there
>
> Anybody knows what is going on with the second b.get()?

What did you expect? Since you've done only one put in the Queue, there's  
nothing left in it. Since queues are meant to communicate between threads  
- and also often to synchronize them -, the default behaviour for the get  
when the queue is empty is to wait for something to be put in it. If you  
want your second get to fail, use the get_nowait method.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"



More information about the Python-list mailing list