我得到了AttributeError:当我在Windows上运行我的程序时,'module'对象没有属性'fork'。我怎样才能解决这个问题?

问题描述 投票:3回答:1

我尝试在os.fork()功能中调用parent(),但它给了我同样的错误。

这是我的代码:

import os

def child():
    print('Hello from child', os.getpid())
    os._exit(0) # else goes back to parent loop

def parent():
    while True:
        newpid = os.fork()
        if newpid == 0:
            child()
        else:
            print('Hello from parent', os.getpid(), newpid)
        if input() == 'q': break

parent()
python fork
1个回答
1
投票

os.fork()is仅适用于Unix。见this

© www.soinside.com 2019 - 2024. All rights reserved.