码迷,mamicode.com
首页 > 编程语言 > 详细

python多进程

时间:2019-04-09 19:07:54      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:spl   async   art   join()   roc   data   mail   one   dem   

技术图片
 1 #!/usr/bin/env python3
 2 # -*- coding: utf-8 -*-
 3 # @Time    : 2019/3/28 11:58
 4 # @Author  : suwy
 5 # @Email   : suwy@cndatacom.com
 6 # @File    : mulitprocess_demo.py
 7 # @Software: PyCharm
 8 
 9 from multiprocessing import Process,Pool
10 import multiprocessing
11 import os
12 
13 def run(name):
14     print("{} pid:{}".format(name,os.getpid()))
15 
16 def run1(data):
17     print("{} say {} pid:{}".format(data[0],data[1],os.getpid()))
18 
19 run("main")
20 pro = Process(target=run,args=("process-1",))
21 pro.start()
22 pro.join()
23 
24 p = Pool(2)
25 for i in range(10):
26     p.apply_async(run,args=(i,))
27 p.close()
28 p.join()
29 print(multiprocessing.cpu_count())
30 map = Pool(2)
31 map.map_async(run1,[("suwy","lkk"),("roc","kdjf"),("swy","dfkj"),("loli","dsfd"),("venix","hello")])
32 map.close()
33 map.join()
多进程代码

 

python多进程

标签:spl   async   art   join()   roc   data   mail   one   dem   

原文地址:https://www.cnblogs.com/swyroc/p/10678512.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!