Multiprocessing queue in py2.7
MRAB
python at mrabarnett.plus.com
Tue Mar 28 15:10:08 EDT 2017
On 2017-03-28 19:51, 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()
> # ---------------
> 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!
>
Insert a print to see what's being passed to f:
def f(q):
print 'Argument is', q
q.put([42, None, 'hello'])
Is it an int?
If it is, have another look at where the process is created and what is
being passed. Print that out too.
More information about the Python-list
mailing list