PYTHON多进程编码结束之进程池POOL
结束昨晚开始的测试。
最后一个POOL。
A,使用POOL的返回结果
#coding: utf-8
import multiprocessing
import time
def func(msg):
print 'msg:', msg
time.sleep(3)
print 'end'
return 'done', msg
if __name__ == '__main__':
pool = multiprocessing.Pool(processes=3)
result = []
for i in xrange(4):
msg = 'hello %d' %(i)
result.append(pool.apply_async(func, (msg, )))
print 'Mark..Mark..Mark...'
pool.close()
pool.join()
print 'Sub-process(es) done.'
for res in result:
print ':::', res.get()
B,多个进程池
#coding: utf-8
import multiprocessing
import time, random, os
def Lee():
print 'Run task Lee-%s' % (os.getpid())
start = time.time()
time.sleep(random.random() * 10)
end = time.time()
print 'Task Lee, runs %0.2f seconds.' % (end - start)
def Marlon():
print 'Run task Marlon-%s' % (os.getpid())
start = time.time()
time.sleep(random.random() * 10)
end = time.time()
print 'Task Marlon, runs %0.2f seconds.' % (end - start)
def Allen():
print 'Run task Allen-%s' % (os.getpid())
start = time.time()
time.sleep(random.random() * 10)
end = time.time()
print 'Task Allen, runs %0.2f seconds.' % (end - start)
def Frank():
print 'Run task Frank-%s' % (os.getpid())
start = time.time()
time.sleep(random.random() * 10)
end = time.time()
print 'Task Frank, runs %0.2f seconds.' % (end - start)
if __name__ == '__main__':
function_list = [Lee, Marlon, Allen, Frank]
print 'parent process %s' % (os.getpid())
pool = multiprocessing.Pool(4)
for func in function_list:
pool.apply_async(func)
print 'Waiting for all subprocess done...'
pool.close()
pool.join()
print 'All subprocesses done.'
截图:

PYTHON多进程编码结束之进程池POOL的更多相关文章
- Python多进程库multiprocessing中进程池Pool类的使用[转]
from:http://blog.csdn.net/jinping_shi/article/details/52433867 Python多进程库multiprocessing中进程池Pool类的使用 ...
- Python多进程库multiprocessing中进程池Pool类的使用
问题起因 最近要将一个文本分割成好几个topic,每个topic设计一个regressor,各regressor是相互独立的,最后汇总所有topic的regressor得到总得预测结果.没错!类似ba ...
- python学习笔记——multiprocessing 多进程组件 进程池Pool
1 进程池Pool基本概述 在使用Python进行系统管理时,特别是同时操作多个文件目录或者远程控制多台主机,并行操作可以节约大量时间,如果操作的对象数目不大时,还可以直接适用Process类动态生成 ...
- python 进程池pool简单使用
平常会经常用到多进程,可以用进程池pool来进行自动控制进程,下面介绍一下pool的简单使用. 需要主动是,在Windows上要想使用进程模块,就必须把有关进程的代码写if __name__ == ‘ ...
- Python多进程库multiprocessing创建进程以及进程池Pool类的使用
问题起因最近要将一个文本分割成好几个topic,每个topic设计一个regressor,各regressor是相互独立的,最后汇总所有topic的regressor得到总得预测结果.没错!类似bag ...
- [转]Python多进程并发操作中进程池Pool的应用
Pool类 在使用Python进行系统管理时,特别是同时操作多个文件目录或者远程控制多台主机,并行操作可以节约大量的时间.如果操作的对象数目不大时,还可以直接使用Process类动态的生成多个进程,十 ...
- Python多进程并发操作中进程池Pool的应用
Pool类 在使用Python进行系统管理时,特别是同时操作多个文件目录或者远程控制多台主机,并行操作可以节约大量的时间.如果操作的对象数目不大时,还可以直接使用Process类动态的生成多个进程,十 ...
- python 全栈开发,Day40(进程间通信(队列和管道),进程间的数据共享Manager,进程池Pool)
昨日内容回顾 进程 multiprocess Process —— 进程 在python中创建一个进程的模块 start daemon 守护进程 join 等待子进程执行结束 锁 Lock acqui ...
- python并发编程之多进程2数据共享及进程池和回调函数
一.数据共享 尽量避免共享数据的方式 可以借助队列或管道实现通信,二者都是基于消息传递的. 虽然进程间数据独立,但可以用过Manager实现数据共享,事实上Manager的功能远不止于此. 命令就是一 ...
随机推荐
- Hive over HBase和Hive over HDFS性能比较分析
http://superlxw1234.iteye.com/blog/2008274 环境配置: hadoop-2.0.0-cdh4.3.0 (4 nodes, 24G mem/node) hbase ...
- 【MINA】用protobuf做编解码协议
SOCKET协议 支持java serial 与 AMF3的混合协议,目前没有基于xml 与 json的实现. 协议说明: * 9个字节协议头+协议体. * * 协议头1-4字节表示协议长度 =协议体 ...
- 【MINA】OrderedThreadPoolExecutor和UnorderedThreadPoolExecutor的事件监听线程池的选择
mina中有两个线程池概念 1.处理监听建立连接的线程池 2.处理读写事件的线程池 本文中主要探讨读写事件的线程池的选择 这两种都经过实际项目的使用和检测,说说优缺点 早期的项目是用Unordere ...
- 解决某些手机RadioGroup中的RadioButton不居中的问题
问题:RadioButton中使用android:gravity="center"使其图片文字居中,在我的华为荣耀7手机上居中显示了,但在HUAWEI G606-T00却显示在右侧 ...
- C#基础总复习01
马上就快毕业了,准备把这几个月所学到的知识梳理一下,这儿所写的都是一些C#中最基础的东西(大牛不要笑话我,这也是我记录的一些笔记等等),希望能帮到一些正在学习这方面的知识的人,如果有写的不对的地方,望 ...
- Oracle PL/SQL 多重选择句
Oracle中语句块的基本格式: declare --变量定义,初始化赋值. begin --变量的赋值,函数调用,if,while等. end: Oracle中的语句:关系运算符:= <> ...
- Custom Action : dynamic link library
工具:VS2010, Installshield 2008 实现功能: 创建一个C++ win32 DLL的工程,MSI 工程需要调用这个DLL,并将Basic MSI工程中的两个参数,传递给DLL, ...
- 1.MySQL的安装(linux Ubuntu环境下)
首先先检验一下系统中是否已经安装有mysql: deamon@deamon-H55M-S2:~$ sudo netstat -tap | grep mysql [sudo] password for ...
- leetcode Maximal Rectangle 单调栈
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ...
- Understanding Manycore Scalability of File Systems
多核场景下,不同文件系统,文件操作的性能评估.