
pipe进程间通信无法接收消息的解决方法
在python中,使用pipe进行进程间通信时,如果父进程无法收到消息,可能原因是参数传递错误。
在提供的问题代码中:
def fun(name):
time.sleep(3)
# 向管道写入内容
fd1.send({name: os.getpid()})这里缺少了管道参数fd1,因此进程fun无法将数据写入管道。
立即学习“Python免费学习笔记(深入)”;
要解决这个问题,只需将fd1参数传给进程fun。
正确的代码如下:
p = Process(target=fun, args=(i, fd1))










