为什么我在管道中收到“IOError:错误消息长度”?

时间:2014-11-06 14:23:47

标签: python pipe fork

我创建了这个程序,用fork将两个矩阵相乘,并用管道将结果报告给父。

程序正常运行,但最后我收到以下错误消息:

File "ep2_fork.py", line 105, in <module>
myVar1 = pipe_pai.recv()
IOError: bad message length

它可能是什么?

(代码的某些部分已被删除,因为它们不需要提问)

import os
from multiprocessing import Pipe

def multiplicacao1(pipe_filho):
    myVar1 = productMatrix(A[0:len(A)/2], B)
    pipe_filho.send(myVar1)

def multiplicacao2(pipe_filho):
    myVar2 = productMatrix(A[len(A)/2:], B)
    pipe_filho.send(myVar2)

matrixSize = random.randint(1, 25)

A = createMatrix(matrixSize)
B = createMatrix(matrixSize)

print "\nAs matrizes geradas foram:\n"

printMatrix(A)
print
printMatrix(B)

pipe_filho, pipe_pai = Pipe()

pid_filho = os.fork()

if pid_filho == 0:
    multiplicacao1(pipe_filho)
    time.sleep(1)

pid_neto = os.fork()

if pid_neto == 0:
    multiplicacao2(pipe_filho)
    time.sleep(1)               

myVar1 = pipe_pai.recv() # Line 105
myVar2 = pipe_pai.recv()

print "\nO produto das duas matrizes e:\n"
printMatrix(myVar1+myVar2)

0 个答案:

没有答案