Python案例-网络编程-进程池
Python的进程池需要借用name方法来实现,具体内容如下#!/usr/bin/env python# -- coding = 'utf-8' --# Author Allen Lee# Python Version 3.5.1# OS Windows 7from multiprocessing import Poolimport timedef f1(arg):time.s
·
Python的进程池需要借用name方法来实现,具体内容如下
#!/usr/bin/env python
# -- coding = 'utf-8' --
# Author Allen Lee
# Python Version 3.5.1
# OS Windows 7
from multiprocessing import Pool
import time
def f1(arg):
time.sleep(1)
print(arg)
if __name__ == '__main__':
pool = Pool(5)
for i in range(30):
pool.apply_async(func=f1,args=(i,))
pool.close()#等待所有任务执行完毕
#time.sleep(1)
#pool.terminate() #立即终止
pool.join()
pass
更多推荐
已为社区贡献10条内容
所有评论(0)