本文介绍了python multiprocessing manager-共享列表-对等104重置连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一位家长启动了两个进程A,B,它们具有应并行运行的python多处理程序.

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

与Multiprocessing.Manager共享两个列表list_1list_2

Share two lists with Multiprocessing.Managerlist_1list_2

对list_1的写操作作为参数传递给A,在A list_1内成为list_W.来自list_2的读取(作为参数传递给A,在list_2内)成为list_RB写入list_2并将其作为参数传递给B,B内部的list_2变为list_W.B从作为参数传递给B的list_1读取,B内的list_1成为list_R

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_RB 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

如果我不是将A或B称为multiprocessing.process,而是将其作为单个函数调用,它们就会运行,从而产生问题.

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

如果我将它们称为multiprocessing.process,则会发生这种情况:

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

watch()比较两个列表的值,但是对于每个程序来说,一个值处于读取状态,一个值处于写入状态,所以我不明白这是什么问题.

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.

推荐答案

如果我添加

A.join()
B.join()

错误消失,程序运行.为什么会这样?

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

这篇关于python multiprocessing manager-共享列表-对等104重置连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:58