Multiprocessing queue in py2.7
Frank Miles
fpm at u.washington.edu
Tue Mar 28 14:51:04 EDT 2017
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()
# ---------------
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 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!
-F
More information about the Python-list
mailing list