Multiprocessing queue in py2.7

Frank Miles fpm at u.washington.edu
Tue Mar 28 16:16:48 EDT 2017


On Tue, 28 Mar 2017 15:38:38 -0400, Terry Reedy wrote:

> On 3/28/2017 2:51 PM, Frank Miles wrote:
>> I tried running a bit of example code from the py2.7 docs
>>   (16.6.1.2. Exchanging objects between processes)
>> only to have it fail.  The code is simply:
>> # ------------
>> from multiprocessing import Process, Queue
>>
>> def f(q):
>>     q.put([42, None, 'hello'])
>>
>> if __name__ == '__main__':
>>     q = Queue()
>>     p = Process(target=f, args=(q,))
>>     p.start()
>>     print q.get()    # prints "[42, None, 'hello']"
>>     p.join()
>> # ---------------
> 
> Cut and pasted, this runs as specified on 2.7.13 on Win 10
> 
>> But what happens is f() fails:
>>
>> Traceback (most recent call last):
>>   File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
>>     self.run()
>>   File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
>>     self._target(*self._args, **self._kwargs)
>>   File "x.py", line 4, in f
>>     q.put([42, None, "Hello"])
>> AttributeError: 'int' object has no attribute 'put'
> 
> This says that the arg bound to q in f is an int rather than a Queue. 
> Are you sure that you posted the code that you ran?
> 
>> This is on a Debian jessie host, though eventually it needs to
>> run on a raspberry pi 3 {and uses other library code that needs
>> py2.7}.
>>
>> Thanks in advance for those marvelous clues!

Argghh!  I missed one stupid typo.  Somehow had a '1' instead of the 'q' in the Process(..)
line.

My bad.  Sorry for the noise, and thanks!!
	-F



More information about the Python-list mailing list