マルチプロセッシングで困っています。私のプログラムの基本的なスキームは次のとおりです。
- 主なプロセス
- メインプロセスから呼び出される並列プロセス
メインプロセスから関数を呼び出そうとする並列プロセス
class MainProcess(): def foo(self): # do something def main(): p = ParallelProcess(self) p.start() class ParallelProcess(multiprocessing.Process): def __init__(self, mainProcess): multiprocessing.Process.__init__(self) self.mainProcess = mainProcess def run(self): self.mainProcess.foo()
私の実際のプログラムはもっと複雑ですが、この例は私のコードの構造を完全に説明しています。私が得るエラーはピクルスと関係があります。私が理解している限り、mainProcess は選択できないため、このタイプのエラーが発生します。ただし、上記以外のどのパターンまたはコード構造を使用すればよいかわかりません。どんな助けでも大歓迎です。
要求された正確なエラーは次のとおりです。
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Program Files\PsychoPy2\lib\multiprocessing\forking.py", line 342, in main
self = load(from_parent)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 1370, in load
return Unpickler(file).load()
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 880, in load_eof
raise EOFError
EOFError
Traceback (most recent call last):
File "C:\Users\user\workspace\Eyelink1.1\gcwindow_main.py", line 17, in <module>
main()
File "C:\Users\user\workspace\Eyelink1.1\gcwindow_main.py", line 9, in main
wrapper.run() # start collecting data on a separate process
File "C:\Users\user\workspace\Eyelink1.1\pylinkwrapper.py", line 149, in run
exp.start()
File "C:\Program Files\PsychoPy2\lib\multiprocessing\process.py", line 104, in start
self._popen = Popen(self)
File "C:\Program Files\PsychoPy2\lib\multiprocessing\forking.py", line 239, in __init__
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "C:\Program Files\PsychoPy2\lib\multiprocessing\forking.py", line 162, in dump
ForkingPickler(file, protocol).dump(obj)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 725, in save_inst
save(stuff)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 419, in save_reduce
save(state)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 681, in _batch_setitems
save(v)
File "C:\Program Files\PsychoPy2\lib\pickle.py", line 306, in save
rv = reduce(self.proto)
ValueError: ctypes objects containing pointers cannot be pickled