i have created sample program generalize issue facing
import multiprocessing multiprocessing import manager def f (_print): print _print manager = multiprocessing.manager() dict = manager.dict() dict['process_obj'] = multiprocessing.current_process() print dict if __name__ == '__main__': process = multiprocessing.process(target=f, args= ('hello function', )) process.start() process.join()
so how store process object in multiprocessing manager.dict()?
i assume you're talking getting error:
hello function process process-1: traceback (most recent call last): file "/usr/local/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap self.run() file "/usr/local/lib/python2.7/multiprocessing/process.py", line 114, in run self._target(*self._args, **self._kwargs) file "mp2.py", line 8, in f dict['process_obj'] = multiprocessing.current_process() file "<string>", line 2, in __setitem__ file "/usr/local/lib/python2.7/multiprocessing/managers.py", line 758, in _callmethod conn.send((self._id, methodname, args, kwds)) picklingerror: can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed
(it's idea include "what got" , "what expected instead" in question).
the fundamental problem here multiprocessing.current_process()
returns instance method. instance methods don't pickle properly, , multiprocessing
has save (pickle) , load (unpickle) shared data items communicate values 1 process another. see, e.g., can't pickle <type 'instancemethod'> when using python's multiprocessing pool.map() , overcoming python's limitations regarding instance methods. note in particular 1 of answers in second: might better figure out state send/share, rather entire instance. instance, if ident
of process suffices, can this:
dict['process_obj'] = multiprocessing.current_process().ident
which works fine.
Comments
Post a Comment