国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python mutiprocessing多線程池pool操作示例

2020-02-16 01:00:06
字體:
供稿:網(wǎng)友

本文實(shí)例講述了Python mutiprocessing多線程池pool操作。分享給大家供大家參考,具體如下:

python — mutiprocessing 多線程 pool

腳本代碼:

root@72132server:~/python/multiprocess# lsmultiprocess_pool.py multprocess.pyroot@72132server:~/python/multiprocess# cat multiprocess_pool.py#!/usr/bin/python# --*-- coding:utf-8 --*--import multiprocessingimport sys,os,timeresult = []#把運(yùn)行的進(jìn)程池放入,空的列表def run(msg):#定義正在處理進(jìn)程編號數(shù)的函數(shù)功能  print 'threading number:%s %s' %(msg,os.getpid())#打印正在處理的進(jìn)程編號數(shù)與對應(yīng)的系統(tǒng)進(jìn)程號  time.sleep(2)p = multiprocessing.Pool(processes = 25)#綁定事例,同時執(zhí)行25個線程for i in range(100):  result.append(p.apply_async(run,('%s' %i,)))#異步傳輸正在運(yùn)行的進(jìn)程數(shù)字號碼p.close()#關(guān)閉正在運(yùn)行的25個進(jìn)程#p.join()for res in result:#獲取運(yùn)行結(jié)果  res.get(timeout=5)root@72132server:~/python/multiprocess#

運(yùn)行情況:

1)腳本運(yùn)行

root@72132server:~/python/multiprocess# python multiprocess_pool.pythreading number:0 27912threading number:1 27915threading number:2 27913threading number:3 27916threading number:4 27917threading number:5 27918threading number:6 27919threading number:7 27920threading number:8 27922threading number:9 27923threading number:10 27924threading number:11 27925threading number:12 27926threading number:13 27927threading number:14 27928threading number:15 27914threading number:16 27929threading number:17 27921threading number:18 27930threading number:19 27931threading number:20 27932threading number:21 27934threading number:22 27935threading number:23 27936threading number:24 27933threading number:25 27912threading number:26 27915threading number:27 27917threading number:28 27918threading number:29 27916threading number:30 27913threading number:31 27922threading number:32 27919threading number:33 27920threading number:34 27923threading number:35 27924threading number:36 27925threading number:37 27927threading number:38 27921threading number:39 27930threading number:40 27932threading number:41 27934threading number:42 27935threading number:43 27926threading number:44 27931threading number:45 27928threading number:46 27929threading number:47 27914threading number:48 27933threading number:49 27936threading number:50 27912threading number:51 27915

2)進(jìn)程查看(25個進(jìn)程同時運(yùn)行)

root@72132server:~/python/multiprocess# ps -ef | grep multiroot   27905 23930 0 22:39 pts/3  00:00:00 grep multiroot@72132server:~/python/multiprocess# ps -ef | grep multiroot   27911 20609 1 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27912 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27913 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27914 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27915 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27916 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27917 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27918 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27919 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27920 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27921 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27922 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27923 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27924 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27925 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27926 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27927 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27928 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27929 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27930 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27931 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27932 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27933 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27934 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27935 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27936 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27941 23930 0 22:39 pts/3  00:00:00 grep multiroot@72132server:~/python/multiprocess# ps -ef | grep multiroot   27911 20609 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27912 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27913 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27914 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27915 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27916 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27917 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27918 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27919 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27920 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27921 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27922 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27923 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27924 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27925 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27926 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27927 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27928 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27929 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27930 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27931 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27932 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27933 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27934 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27935 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27936 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.pyroot   27943 23930 0 22:39 pts/3  00:00:00 grep multiroot@72132server:~/python/multiprocess#            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 建始县| 泽州县| 潼关县| 河津市| 泸西县| 阜新| 宜黄县| 达尔| 剑河县| 慈溪市| 广安市| 平舆县| 布拖县| 鹤山市| 新巴尔虎左旗| 兰州市| 文水县| 浑源县| 吴忠市| 米林县| 江源县| 河津市| 加查县| 台东市| 中卫市| 池州市| 那坡县| 英德市| 忻城县| 大方县| 元江| 泾川县| 饶阳县| 湖南省| 鲁甸县| 克东县| 黄平县| 昆明市| 黄浦区| 新竹市| 通河县|