快速子进程库
fastprocess的Python项目详细描述
快速处理
快速子流程库
用法
使用fastprocess生成进程非常简单
In [1]: from fastprocess import FastProcess
In [2]: pid = FastProcess(['echo', 'hello', 'world'])
hello world
In [3]: pid.wait()
Out[3]: 0
您可以使用stdin、stdout和stderr选项重定向io
In [4]: null = open('/dev/null', 'w')
In [5]: pid = FastProcess(['yes'], stdout=null)
In [6]: pid.terminate()
fp方法
终止():
将sigterm发送到进程
杀死(sig):
向进程发送信号“sig”
等待():
等待进程退出,然后返回退出代码
性能
下面是运行的结果./benchmark/bench
---------------------------------------
10000 spawns with fork and exec...
real 0m2.214s
user 0m0.083s
sys 0m2.123s
---------------------------------------
10000 spawns with fastprocess...
real 0m3.163s
user 0m0.383s
sys 0m2.772s
---------------------------------------
10000 spawns with subprocess...
real 0m11.110s
user 0m6.773s
sys 0m7.772s
---------------------------------------