本文实例讲述了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 = []#把运行的进程池放入,空的列表 def run(msg):#定义正在处理进程编号数的函数功能 print 'threading number:%s %s' %(msg,os.getpid())#打印正在处理的进程编号数与对应的系统进程号 time.sleep(2) p = multiprocessing.Pool(processes = 25)#绑定事例,同时执行25个线程 for i in range(100): result.append(p.apply_async(run,('%s' %i,)))#异步传输正在运行的进程数字号码 p.close()#关闭正在运行的25个进程 #p.join() for res in result:#获取运行结果 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)进程查看(25个进程同时运行)
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#
更多关于Python相关内容感兴趣的读者可查看本站专题:《Python进程与线程操作技巧总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》、《Python+MySQL数据库程序设计入门教程》及《Python常见数据库操作技巧汇总》
希望本文所述对大家Python程序设计有所帮助。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“Python mutiprocessing多线程池pool操作示例”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2025年04月26日
2025年04月26日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]