1. 程式人生 > >windows os.fork(), AttributeError: module 'os' has no attribute 'fork'

windows os.fork(), AttributeError: module 'os' has no attribute 'fork'

AttributeError: module 'os' has no attribute 'fork'
import os

print('Process (%s) start...' % os.getpid())
# Only works on Unix/Linux/Mac:
pid = os.fork()  #不要在windows系統中使用,會出錯,
if pid == 0:
    print('I am child process (%s) and my parent is %s.' % (os.getpid(), os.getppid()))
else:
    print('I (%s) just created a child process (%s).' % (os.getpid(), pid))

os.fork()方法,使用在linux /Unix系統,不在windows下使用,如果在windows下使用,報錯;

Process (21132) start...
Traceback (most recent call last):
  File "E:/soft/pycharm/workplace/1.py", line 5, in <module>
    pid = os.fork()
AttributeError: module 'os' has no attribute 'fork'