python multiprocessing manager - shared list - connection reset by peer 104

二次信任 提交于 2021-02-10 05:16:08

问题


One parent launch two process A, B with python multiprocessing that should run in parallel.

Share two lists with Multiprocessing.Manager list_1 list_2

A write to list_1 that is passed as parameter to A, inside A list_1 became list_W. A read from a list_2 that is passed as parameter to A, inside A list_2 became list_R B write to list_2 that is passed as parameter to B, inside B list_2 became list_W. B read from a list_1 that is passed as parameter to B, inside B list_1 became list_R

if I call A or B not as multiprocessing.process but as single function, they run, whitout problems.

if I call them as multiprocessing.process this is what happen:

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 "myprg/A.py", line 47, in A
    watch()                                                         
  File "myprg/DEFINITIONS.py", line 87, in watch
    if list_W[0] != list_R[0]:
  File "<string>", line 2, in __getitem__
  File "/usr/lib/python2.7/multiprocessing/managers.py", line 759, in _callmethod
    kind, result = conn.recv()
IOError: [Errno 104] Connection reset by peer

The watch() compare the two lists values, but as one is in read and one in write for each program, I can't understand what it is the problem.


回答1:


if I add

A.join()
B.join()

the error disappear and the program run. Why this behavior?



来源:https://stackoverflow.com/questions/17172241/python-multiprocessing-manager-shared-list-connection-reset-by-peer-104

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!