我使用Python3.4的os.pipe来实现父子进程间的进程间通信,通过os.execlp args传递管道参数。
self.child_pipe_read=int(sys.argv[2])
self.child_pipe_write=int(sys.argv[3])
...
os.execlp('python3','python3','child_test.py',str(pid),str(self.child_pipe_read) ,str(self.child_pipe_write))
然而,当我使用这个时:
msg=os.read(self.child_pipe_read,32)
抛出错误 OSError: [Errno 9] 坏的文件描述符
然后我尝试向管道写入:
os.write(self.parent_pipe_write,(msg+'\n').encode())
BrokenPipeError: [Errno 32] Broken pipe
翻译:管道破裂错误:[Errno 32] 管道破裂
我看到了Python3.4的文档,发现这个内容:
"从3.4版本开始更改:新的文件描述符现在是不可继承的",但我不知道它的含义是什么?如何使用管道进行进程间通信?
翻译: "从3.4版本开始更改:新的文件描述符现在是不可继承的",但我不知道它的含义是什么?如何使用管道进行进程间通信?