multiprocessing problem: queue.get() not finding pushed values

Charles Hixson charleshixsn at earthlink.net
Wed Jul 16 07:47:10 CEST 2014


On 07/15/2014 09:26 PM, Chris Angelico wrote:
> On Wed, Jul 16, 2014 at 6:32 AM, Charles Hixson
> <charleshixsn at earthlink.net> wrote:
>> from queue import Empty, Full
> Not sure what this is for, you never use those names (and I don't have
> a 'queue' module to import from). Dropped that line. In any case, I
> don't think it's your problem...
>
>> if __name__ == "__main__":
>>      dbw    =    DBW(DBW_to, DBW_from)
>>      dbw.run()
>>      DBW_to.put(Msg("a", 1, wrd) )
>>      DBW_to.put(Msg("b", 2, wrd) )
>>      DBW_to.put(Msg("c", 0, None) )
> ... which is here. You're not starting a subprocess; you're simply
> calling a method, so it runs synchronously. When you call .run(), it
> runs the "subprocess" to completion, which then bombs because the
> queue's empty, and then never gets to putting anything onto it. Change
> that .run() to .start() and it'll do as you expect, except that as
> part of cutting the example down you seem to have omitted the
> definition of wrd. I changed that to a quoted string and it works:
>
> # chomp unchanged code ...
> if __name__ == "__main__":
>      dbw    =    DBW(DBW_to, DBW_from)
>      dbw.start()
>      DBW_to.put(Msg("a", 1, 'wrd') )
>      DBW_to.put(Msg("b", 2, 'wrd') )
>      DBW_to.put(Msg("c", 0, None) )
>
> rosuav at sikorsky:~$ python test7a.py
> msg = Msg(act='a', id=1, vals='wrd')
>
> Hope that helps!
>
> ChrisA
Thank you.  I had forgotten that one wasn't supposed to call run directly.
FWIW, I import Empty and Full because the multiprocessor documentations 
says in


      17.2.2.2. Pipes and Queues

Note

multiprocessing <cid:part1.05080901.05000005 at earthlink.net> uses the 
usual queue.Empty <cid:part2.06060100.00020506 at earthlink.net> and 
queue.Full <cid:part3.01060608.01040702 at earthlink.net> exceptions to 
signal a timeout. They are not available in the multiprocessing 
<cid:part1.05080901.05000005 at earthlink.net> namespace so you need to 
import them from queue <cid:part5.09090108.07050309 at earthlink.net>.

They aren't used in the stripped down test, but they are used in the 
real code
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140715/d36c4074/attachment.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140715/d36c4074/attachment-0001.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140715/d36c4074/attachment-0002.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140715/d36c4074/attachment-0003.html>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140715/d36c4074/attachment-0004.html>


More information about the Python-list mailing list