结束昨晚开始的测试。

最后一个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的更多相关文章

  1. Python多进程库multiprocessing中进程池Pool类的使用[转]

    from:http://blog.csdn.net/jinping_shi/article/details/52433867 Python多进程库multiprocessing中进程池Pool类的使用 ...

  2. Python多进程库multiprocessing中进程池Pool类的使用

    问题起因 最近要将一个文本分割成好几个topic,每个topic设计一个regressor,各regressor是相互独立的,最后汇总所有topic的regressor得到总得预测结果.没错!类似ba ...

  3. python学习笔记——multiprocessing 多进程组件 进程池Pool

    1 进程池Pool基本概述 在使用Python进行系统管理时,特别是同时操作多个文件目录或者远程控制多台主机,并行操作可以节约大量时间,如果操作的对象数目不大时,还可以直接适用Process类动态生成 ...

  4. python 进程池pool简单使用

    平常会经常用到多进程,可以用进程池pool来进行自动控制进程,下面介绍一下pool的简单使用. 需要主动是,在Windows上要想使用进程模块,就必须把有关进程的代码写if __name__ == ‘ ...

  5. Python多进程库multiprocessing创建进程以及进程池Pool类的使用

    问题起因最近要将一个文本分割成好几个topic,每个topic设计一个regressor,各regressor是相互独立的,最后汇总所有topic的regressor得到总得预测结果.没错!类似bag ...

  6. [转]Python多进程并发操作中进程池Pool的应用

    Pool类 在使用Python进行系统管理时,特别是同时操作多个文件目录或者远程控制多台主机,并行操作可以节约大量的时间.如果操作的对象数目不大时,还可以直接使用Process类动态的生成多个进程,十 ...

  7. Python多进程并发操作中进程池Pool的应用

    Pool类 在使用Python进行系统管理时,特别是同时操作多个文件目录或者远程控制多台主机,并行操作可以节约大量的时间.如果操作的对象数目不大时,还可以直接使用Process类动态的生成多个进程,十 ...

  8. python 全栈开发,Day40(进程间通信(队列和管道),进程间的数据共享Manager,进程池Pool)

    昨日内容回顾 进程 multiprocess Process —— 进程 在python中创建一个进程的模块 start daemon 守护进程 join 等待子进程执行结束 锁 Lock acqui ...

  9. python并发编程之多进程2数据共享及进程池和回调函数

    一.数据共享 尽量避免共享数据的方式 可以借助队列或管道实现通信,二者都是基于消息传递的. 虽然进程间数据独立,但可以用过Manager实现数据共享,事实上Manager的功能远不止于此. 命令就是一 ...

随机推荐

  1. Ubuntu 安装php mcrypt

    sudo apt-get install php5-mcrypt libmcrypt4 libmcrypt-dev sudo php5enmod mcrypt sudo /etc/init.d/apa ...

  2. dedecms内容管理

    dedecms中的内容模型是指文章.软件.商品等类型的文章字段模板.在dedecms中,文章数据由文章主表和文章附加表构成,主表存放文章公共拥有的信息,比如标题,添加时间,点击量等,文章附加表存放文章 ...

  3. react 全局面包屑

    renderBreadcrumb() { const {routes} = this.props; const items = routes.map((route, idx) => { let ...

  4. asp.net服务器页面处理过程

    一.静态页面.动态页面区别 静态页面是服务端直接从硬盘里面读取然后发回去,动态页面就要创建这个页面类的对象,调用对象的方法,方法里面什么就发回什么.浏览器请求asp.net页面实际是请求asp.net ...

  5. android NDK 笔记

    *************************************************华丽的分割线********************************************* ...

  6. SQLite 入门教程(一)基本控制台(终端)命令

    一.基本简介 SQLite 是一个自持的(self-contained).无服务器的.零配置的.事务型的关系型数据库引擎.因为他很小,所以也可以作为嵌入式数据库内建在你的应用程序中.SQLite 被应 ...

  7. 如何给windows窗体程序打包成一个安装包

    http://blog.csdn.net/xyy410874116/article/details/6341787 给windows窗体程序打包成一个安装包:具体操作在:http://hi.baidu ...

  8. 修改arcgis server默认js和css连接地址

    当使用ArcGIS Server 10.1发布了一个地图服务之后,在ArcGIS Server 10.1的机器上使用浏览器进入http://localhost:6080/arcgis/rest/ser ...

  9. 牛客_剑指offer_重建二叉树,再后续遍历_递归思想_分两端

       总结:    重建二叉树:其实就是根据前序和中序重建得到二叉树,得到后续,只要输出那边设置输出顺序即可 [编程题]重建二叉树 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的 ...

  10. 一 JavaScript应用开发实践指南

    渐进增强模型 总述: 结构层(Structure),表现层(presentation)与行为层(behavior). HTML,CSS,JavaScript. 只有HTML 的情况下也可以显示内容,C ...