作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如何在 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'
最佳答案
os.fork
仅适用于类 Unix 系统。你不能在 Windows 中使用它。
os.fork()
Fork a child process. Return 0 in the child and the child’s process id in the parent. If an error occurs OSError is raised.
Note that some platforms including FreeBSD <= 6.3, Cygwin and OS/2 EMX have known issues when using fork() from a thread.
Availability: Unix.
关于python - 我如何在 Python3.3 中使用 fork(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19547443/
我是一名优秀的程序员,十分优秀!