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

MRAB google at mrabarnett.plus.com
Wed Oct 15 17:22:13 CEST 2008


On Oct 15, 2:05 pm, redbaron <ivanov.ma... 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)

>From Python v2.5 onwards queues also have a task_done() method. Try:

while qresult.qsize():
    result = qresult.get()  #this code blocks!
    doWithResult(result)
    qresult.task_done()



More information about the Python-list mailing list