python线程池操作_Python mutiprocessing多线程池pool操作示例
本文实例讲述了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 mutiprocessing多线程池pool操作示例相关推荐
- python连接池框架_python pymysql 连接池
采用连接池的方式来操作DB #-*- coding:utf-8 -*- #!/usr/bin/python3 import pymysql import configUtil from DBUtils ...
- python 线程 的类库_python类库32[多线程]
一 python 多线程 因为CPython的实现使用了Global Interpereter Lock(GIL),使得python中同一时刻只有一个线程在执行,从而简化了python解释器的实现,且 ...
- python通过ip池爬_Python爬虫 | IP池的使用
一.简介 爬虫中为什么需要使用代理 一些网站会有相应的反爬虫措施,例如很多网站会检测某一段时间某个IP的访问次数,如果访问频率太快以至于看起来不像正常访客,它可能就会禁止这个IP的访问.所以我们需要设 ...
- python打开一个软件并进行操作_python程序中的进程操作
之前我们已经了解了很多进程相关的理论知识,了解进程是什么应该不再困难了,刚刚我们已经了解了,运行中的程序就是一个进程.所有的进程都是通过它的父进程来创建的.因此,运行起来的python程序也是一个进程 ...
- python 线程超时设置_python多任务之总结——(二)线程、协程
本文主要讲述进程线程协程在python中的使用.主要说明各自的创建.通信及联系与区别,了解各自的适用场景,能更好的利用并发实现多任务开发. 第一部分:python多任务之总结--(一)进程学习 线程 ...
- python数据库环境详解_python中MySQL数据库相关操作
一 安装基本环境 1 简介 MySQL 基于TCP 协议之上的开发,但是网络连接后,传输的数据必须遵循MySQL的协议,封装好MySQL协议的包,就是驱动程序 MySQL 的驱动 MySQLDB 最有 ...
- python 线程超时设置_python 条件变量Condition(36)
文章首发微信公众号,微信搜索:猿说python 对于线程与线程之间的交互我们在前面的文章已经介绍了 python 互斥锁Lock / python事件Event , 今天继续介绍一种线程交互方式 – ...
- python控制其它软件_python——实现ERP软件自动化操作
软件部分.png 数据部分.png erp软件操作是个繁琐至极的工作,也许能带来整体数据的优化,但操作十分死板和无聊,通过python中pyautogui和pyopenxl两个包,可以将操作部分实现自 ...
- python pandas excel 排序_Python pandas对excel的操作实现示例
最近经常看到各平台里都有Python的广告,都是对excel的操作,这里明哥收集整理了一下pandas对excel的操作方法和使用过程.本篇介绍 pandas 的 DataFrame 对列 (Colu ...
最新文章
- Anaconda入门使用指南(一)
- mysql 协议的ResultsetRow包及解析
- mysql 设置表的大小_mysql InnoDB建表时设定初始大小的方法
- OpenCV Windows Pack but it has no binaries compatible with your configuratio
- java多线程学习-java.util.concurrent详解
- 如果我是面试官,我会问你 Spring 那些问题?
- 网站域名过户查询_网站建设哪家好?网站建设怎么收费?
- GIMP中的新建Layer与更改Layer大小
- 妙用世界之窗浏览器的隐私保护功能
- 用户DSN、 系统DSN 、文件DSN
- s时钟画布 android,Canvas画布实现自定义时钟效果
- java调用tuxedo中间件,BEA-TUXEDO中间件介绍.ppt
- 编译WINDOWS版SDL2:You should run hg revert SDL_config.h
- 微信小程序反编译获取前端代码
- Ubuntu 16.04 创建无线热点
- 零基础如何快速入门python(学习路线)
- ef core连接Oracle数据库
- libuv介绍与编译
- 龙芯的3A5000:中国的最佳拍档?
- 120年奥运会数据分析
热门文章
- 递归判断一个数是否递增
- 2017年网易校招题 买苹果
- mysql install安装报错_mysql安装报错
- java that关键字_Java中this关键字的几种用法
- 用jsp实现右导航窗格_手机导航如何投放到汽车中控屏?建议用这2种办法,轻松实现同屏...
- rpc协议微服务器,RPC协议及实现方式(分布式微服务治理的核心)
- jq获取id的名称_查找 Linux 发行版名称、版本和内核详细信息 | Linux 中国
- double类型占几个字节_MongoDB 中的数据类型
- github单独下载某个文件或文件夹
- scikit-learn流形学习手写数字可视化