【问题标题】:Why is the alternative of fork() system call in python for windows? [duplicate]为什么 fork() 系统调用在 windows 的 python 中的替代品? [复制]
【发布时间】:2019-01-05 22:54:35
【问题描述】:

这是我的代码在 windows 中不起作用。我应该用什么来代替 fork

import os

print("Process id before forking: {}".format(os.getpid()))

try:
    pid = os.fork()
except OSError:
    exit("Could not create a child process")

if pid == 0:
    print("In the child process that has the PID {}".format(os.getpid()))
    exit()

print("In the parent process after forking the child {}".format(pid))
finished = os.waitpid(0, 0)
print(finished)

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    pythonmultiprocessing 模块是通用的,可能对您有用。如需进一步阅读,请查看此link

    此外,Cygwin 重新创建了它,但我不推荐它,因为它很难实现,但是,如果你想了解它,这里是 link

    【讨论】:

    • 但它对fork一无所知。日志中的错误说。 pid = os.fork() AttributeError: module 'os' has no attribute 'fork'
    猜你喜欢
    • 2016-04-30
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    • 2012-01-13
    相关资源
    最近更新 更多