我如何在 Python3.3 中使用 fork() **这是我的代码:
输入:
#!/usr/bin/env python
import os
def Child_process():
print("We are in Child_Process")
print("My PID: %d"%os.getpid())
print("Child_Process is exiting")
def Parent_process():
print("-------Parent_process---------")
wpid = os.fork()
if wpid==0:
print("wpid is 0 means We are in Child_process")
print("Child :%d"%wpid)
Child_process()
else:
print("Execute Parent_process")
print("Parent_process %d"%wpid)
Parent_process()
Parent_process()
输出:
C:\Python33\python.exe C:/Users/Iem-Prog/Desktop/Py/Fork
Traceback (most recent call last):
File "C:/Users/Iem-Prog/Desktop/Py/Fork", line 21, in <module>
-------Parent_process---------
Parent_process()
File "C:/Users/Iem-Prog/Desktop/Py/Fork", line 11, in Parent_process
wpid = os.fork()
AttributeError: 'module' object has no attribute 'fork'