在父os.closewOSError中:[Errno 9]错误的文件描述符为什么我尝试在父子进程之间进行管道传输时出现此错误?

问题描述

导入操作系统 从多处理导入管道 导入系统 导入时间

def child(w):

    msg = ("Spam").encode()
    os.write(w,msg)

def parent():

    r,w = os.pipe()
    Pn = os.fork()
    while True:
        # -------------------------------------------------------------------

        if Pn < 0:
            print("error occured")
        if Pn == 0:

            os.close(r)
            child(w)

            

        else:

            os.close(w)
            pipein = os.fdopen(r)

            line = pipein.readline()
            print("Parent %d got [%s] at %s" %
                  (os.getpid(),line,time.time()))
parent()

自从我使用os.close(r)以来,我认为这是一个问题,但我不知道如何以及为什么。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)