0
A
回答
2
我不知道Python,但我觉得你这样做,就像你做它在C,通过检查的fork()
返回值:如果你想在孩子执行一些代码
child_pid = os.fork()
if child_pid == 0:
print "This is the child."
sys.exit(0)
print "This is the parent."
3
流程,使用multiprocessing
模块。下面是一个例子,从文档:
from multiprocessing import Process
def f(name):
print 'hello', name
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
这个例子说明如何使用函数˚F可以在子进程中执行。
相关问题
- 1. 什么是C?:operator的Ruby等价物?
- 2. Go defer的ruby等价物是什么?
- 3. 什么是PHP $ _ENV的Ruby等价物?
- 4. 什么是Ruby的substr等价物?
- 5. 什么是preg_quote()的Ruby等价物?
- 6. 什么是Ruby中的“sys.stdout.write()”等价物?
- 7. 什么是Python的os.walk的等价物?
- 8. 什么是Python os.pathsep的等价物?
- 9. 什么是Tomcat的Python等价物?
- 10. python中'gem'的等价物是什么?
- 11. 什么是java.util.zip.Inflater的Python等价物?
- 12. Python中imadjust的等价物是什么?
- 13. python中print_r()的等价物是什么?
- 14. Ruby中Python的itertools.product的等价物是什么?
- 15. 什么是Python的urllib.quote_plus的Ruby/Rails等价物?
- 16. 什么是Python的输出[: - 1]的Ruby等价物?
- 17. 什么是Ruby的“检查”的Python等价物?
- 18. 什么是python setup.py开发的Ruby等价物?
- 19. Ruby中Python文档字符串的等价物是什么?
- 20. 是否有“python -i”的ruby等价物?
- 21. Ruby的等价于Python的多处理模块是什么?
- 22. Python的延续与Ruby的等价物
- 23. Python的等价物Ruby的each_slice(count)
- 24. Python中的“require”(Ruby)等价于什么?
- 25. 什么是PHP的preg_quote的等价物?
- 26. MessageFormat的Pattern.quote()的等价物是什么?
- 27. 什么是Ruby的Dir.glob()最简洁的Clojure等价物?
- 28. 什么是Java的StringReader的Ruby等价物?
- 29. 什么是Ruby的“检查”的JavaScript等价物?
- 30. Haskell中Ruby的pnormaldist统计函数的等价物是什么?
通过这种方式,子进程也会打印出“This is the parent。”。我如何确保“fork block”之外的任何内容不会在子进程*中执行。 – satoru 2012-08-12 11:18:46
不,这是父母打印“这是父母”。子进入该行之前调用'sys.exit(0)'。它是通过退出块的最后一个孩子,你确保孩子除了块之外什么都不执行。 – 2012-08-12 11:24:39