开发者社区> 问答> 正文

multiprocess test


import os
from multiprocessing import Process,Pool
import time,random


def fun_proc(process_name):
    print 'child process is %s, process ID is %s' %(process_name,os.getpid())
    start=time.time()
    time.sleep(random.random()*3)
    end=time.time()
    print 'task %s runs %0.2f seconds.' %(process_name,(end-start))
    print 'child process work end!'




print  'Parents process ID is %s' % os.getpid()
print  'Parent process start working'
p=Pool(5)
for i in range(7):
    p.apply_async(fun_proc,args=(i,))
    pass


print 'child process start working'
p.close()
p.join()
print  'Parent process work end'

展开
收起
英为 2017-08-26 13:45:53 2373 0
0 条回答
写回答
取消 提交回答
问答地址:
相关问答
706
1
0
1830
0
0
563
1
0
2145
0
0
问答排行榜
最热
最新

相关电子书

更多
How to Build a Successful Data 立即下载
The Value of Exploratory Data 立即下载
How to Build a Successful Data Lake 立即下载