Multiprocessing Queue strange behavior

Bruno Oliveira nicoddemus at gmail.com
Wed Sep 15 22:10:59 CEST 2010


Hi list,

I recently found a bug in my company's code because of a strange behavior
using multiprocessing.Queue. The following code snippet:

from multiprocessing import Queue

queue = Queue()
queue.put('x')
print queue.get_nowait()

Fails with:

...
  File
"E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py",
line 153, in getNoWait
    return self.get(False)
  File
"E:\Shared\dist-0902\i686.win32\processing-0.52\lib\site-packages\processing\queue.py",
line 129, in get
    raise Empty
Queue.Empty

Strangely, changing this to:

queue = Queue()
queue.put('x')
time.sleep(0.1) # <<<
print queue.get_nowait()

Works as expected. Using the original snippet changing the import to
threading's Queue also works.

It seems like there's a bug in multiprocessing's Queue implementation.
Opinions?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100915/beaad9c0/attachment.html>


More information about the Python-list mailing list