multiprocessing: queue.get() blocks even if queue.qsize() != 0

Antoon Pardon apardon at forel.vub.ac.be
Mon Oct 20 04:10:12 EDT 2008


On 2008-10-15, redbaron <ivanov.maxim at gmail.com> wrote:
> I run into problem with queue from multiprocessing. Even if I
> queue.qsize() != 0 queue.get() still blocks and queue.get_nowait()
> raises Emtpy error.
>
> I'm unable to cut my big part to small test case, because smaller test
> case similair to my real app by design is works. In what conditions is
> it possible?
>
> while qresult.qsize():
>     result = qresult.get()  #this code blocks!
>     doWithResult(result)

If you have more than one consumer the above code can block.
The two consumers both see that there is an item present
in the queue. One removes the item and the second blocks.

-- 
Antoon Pardon



More information about the Python-list mailing list