我怎樣才能在Python3.3 使用fork()**這是我的代碼:我怎樣才能在Python3.3
輸入:
#!/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'
您使用哪種操作系統?例如,這在windows下是不可能的。 – User
調查'subprocess'和'multiprocessing'模塊。 – zwol
這是一件好事,它沒有奏效,因爲它無限自稱,變成叉子炸彈。 – interjay