最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python mutiprocessing多線程池pool操作示例

 更新時間:2019年01月30日 12:10:13   作者:徐為波  
這篇文章主要介紹了Python mutiprocessing多線程池pool操作,結(jié)合實例形式分析了Python多線程模塊multiprocessing進(jìn)程池相關(guān)操作技巧,需要的朋友可以參考下

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

python — mutiprocessing 多線程 pool

腳本代碼:

root@72132server:~/python/multiprocess# ls
multiprocess_pool.py multprocess.py
root@72132server:~/python/multiprocess# cat multiprocess_pool.py
#!/usr/bin/python
# --*-- coding:utf-8 --*--
import multiprocessing
import sys,os,time
result = []#把運行的進(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,)))#異步傳輸正在運行的進(jìn)程數(shù)字號碼
p.close()#關(guān)閉正在運行的25個進(jìn)程
#p.join()
for res in result:#獲取運行結(jié)果
  res.get(timeout=5)
root@72132server:~/python/multiprocess#

運行情況:

1)腳本運行

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

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

root@72132server:~/python/multiprocess# ps -ef | grep multi
root   27905 23930 0 22:39 pts/3  00:00:00 grep multi
root@72132server:~/python/multiprocess# ps -ef | grep multi
root   27911 20609 1 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27912 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27913 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27914 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27915 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27916 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27917 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27918 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27919 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27920 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27921 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27922 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27923 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27924 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27925 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27926 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27927 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27928 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27929 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27930 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27931 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27932 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27933 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27934 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27935 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27936 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27941 23930 0 22:39 pts/3  00:00:00 grep multi
root@72132server:~/python/multiprocess# ps -ef | grep multi
root   27911 20609 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27912 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27913 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27914 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27915 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27916 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27917 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27918 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27919 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27920 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27921 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27922 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27923 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27924 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27925 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27926 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27927 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27928 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27929 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27930 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27931 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27932 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27933 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27934 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27935 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27936 27911 0 22:39 pts/1  00:00:00 python multiprocess_pool.py
root   27943 23930 0 22:39 pts/3  00:00:00 grep multi
root@72132server:~/python/multiprocess#

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python進(jìn)程與線程操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》、《Python+MySQL數(shù)據(jù)庫程序設(shè)計入門教程》及《Python常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家Python程序設(shè)計有所幫助。

相關(guān)文章

  • Python3內(nèi)置函數(shù)chr和ord實現(xiàn)進(jìn)制轉(zhuǎn)換

    Python3內(nèi)置函數(shù)chr和ord實現(xiàn)進(jìn)制轉(zhuǎn)換

    這篇文章主要介紹了Python3內(nèi)置函數(shù)chr和ord實現(xiàn)進(jìn)制轉(zhuǎn)換,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • Python調(diào)用JavaScript代碼的方法

    Python調(diào)用JavaScript代碼的方法

    這篇文章主要介紹了Python調(diào)用JavaScript代碼的方法,幫助大家在不同場景里,采用的最佳調(diào)用方式,提高程序的性能,感興趣的朋友可以了解下
    2020-10-10
  • Python DES加密實現(xiàn)原理及實例解析

    Python DES加密實現(xiàn)原理及實例解析

    這篇文章主要介紹了Python DES加密實現(xiàn)原理及實例解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-07-07
  • Python爬蟲實現(xiàn)(偽)球迷速成

    Python爬蟲實現(xiàn)(偽)球迷速成

    還有4天就世界杯了,作為一個資深(偽)球迷,必須要實時關(guān)注世界杯相關(guān)新聞,了解各個球隊動態(tài),下面小編給大家?guī)砹薖ython爬蟲實現(xiàn)(偽)球迷速成功能,一起看看吧
    2018-06-06
  • python實戰(zhàn)之制作表情包游戲

    python實戰(zhàn)之制作表情包游戲

    想知道如何制作表情包游戲嗎?用Python就可以搞定!本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-09-09
  • 淺談Pycharm最有必要改的幾個默認(rèn)設(shè)置項

    淺談Pycharm最有必要改的幾個默認(rèn)設(shè)置項

    今天小編就為大家分享一篇淺談Pycharm最有必要改的幾個默認(rèn)設(shè)置項,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • 一篇文章教你用Python實現(xiàn)一鍵文件重命名

    一篇文章教你用Python實現(xiàn)一鍵文件重命名

    這篇文章主要介紹了如何用python一鍵文件重命名,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Python讀取Excel批量寫入到PPT并生成詞卡

    Python讀取Excel批量寫入到PPT并生成詞卡

    這篇文章主要為大家詳細(xì)介紹了如何使用Python實現(xiàn)讀取Excel并批量寫入到PPT生成詞卡,文中的示例代碼講解詳細(xì),有需要的小伙伴可以參考一下
    2024-12-12
  • python計算程序開始到程序結(jié)束的運行時間和程序運行的CPU時間

    python計算程序開始到程序結(jié)束的運行時間和程序運行的CPU時間

    這篇文章主要介紹了python計算程序開始到程序結(jié)束的運行時間和程序運行的CPU時間的三個方法,大家參考使用
    2013-11-11
  • Python利用PyAutoGUI輕松搞定圖片上傳

    Python利用PyAutoGUI輕松搞定圖片上傳

    PyAutoGUI作為一個GUI操作的神器,我們看到了它的操作都很簡單,非常通俗易懂,基本上看到函數(shù)就能知道它的功效。本文將用它實現(xiàn)圖片上傳功能,感興趣的可以了解一下
    2022-09-09

最新評論

华坪县| 乐安县| 攀枝花市| 武邑县| 克拉玛依市| 鄂尔多斯市| 新巴尔虎左旗| 平阴县| 忻城县| 广德县| 五台县| 昂仁县| 陆良县| 柳河县| 碌曲县| 罗平县| 大兴区| 彭州市| 涿鹿县| 定州市| 汽车| 青岛市| 满城县| 佛冈县| 彩票| 通化县| 十堰市| 莱西市| 漳平市| 吉木乃县| 松原市| 黑龙江省| 彭州市| 嵩明县| 威远县| 汕头市| 开封市| 双柏县| 厦门市| 延寿县| 镶黄旗|