fork in Python
来源:互联网 发布:牌匾设计软件 编辑:程序博客网 时间:2024/06/11 01:31
fork 是
1、有时,程序在一个进程中运行可能会遇到一些问题。如进程可能会占用过多的内存或者打开太多的文件,或者根本无法运行。
2、一般来说,需要将进程分为两个,在子进程中执行一些代码,然后向父进程总返回结果。
3、代码
#!/usr/bin/env pythonimport os, sysprint "I'm going to fork now - the child will write something to a pipe, and the parent will read it back"r, w = os.pipe() # these are file descriptors, not file objectspid = os.fork()if pid: # we are the parent os.close(w) # use os.close() to close a file descriptor r = os.fdopen(r) # turn r into a file object print "parent: reading" txt = r.read() os.waitpid(pid, 0) # make sure the child process gets cleaned upelse: # we are the child os.close(r) w = os.fdopen(w, 'w') print "child: writing" w.write("here's some text from the child") w.close() print "child: closing" sys.exit(0)print "parent: got it; text =", txt
- fork in Python
- python fork
- python fork
- python fork
- USE FORK IN LINUX
- fork in Linux
- python 的os.fork()
- python fork os.pipe()
- python os.fork()
- python 创建进程fork
- python fork()多进程
- Python Imaging Library (Fork)
- Python fork 操作
- Python多线程之fork
- Python fork 守护进程<转>
- Python 多进程 fork()详解
- python os.fork() 循环输出
- python fork子进程(一)
- Android中PopupWindow的用法(位置、动画、焦点)
- VS快捷键
- 黑马程序员13-写在进黑马之前
- php 获取一个文件中return array() 的值
- 多信息显示-ExpandableListView的使用
- fork in Python
- JavaScript面向对象程序设计
- C# 如何让任务栏上的窗口闪动起来
- 解析单例模式(1)
- C++中重载数组下标访问操作符[ ] 和 赋值操作符 = ,* 和 -> 操作符和取反 !以及转化操作符bool和void*
- Android 应用APP界面设计思路
- android-隐藏或显示软键盘
- ubuntu下安装配置 ACE-5.7.8
- Mac OS X 10.8.1 Mountain Lion中svn命令缺失导致Xcode的SVN不能配置的解决办法