结束昨晚开始的测试。

最后一个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. [记录]calculate age based on date of birth

    calculate age based on date of birth know one new webiste:eval.in run php code

  2. arclist底层模板字段,可以调用的字段列表

    arclist底层模板字段,可以调用的字段列表   用DedeCMS做站,arclist是用得最多的标签,因为他是调用文章的基本标签,功能也非常强大,他的底层字段比较多,我们平时使用还没有用到一半,但 ...

  3. js中 this篇

    以下文案皆来自<你不知道的JavaScript 上卷>——读书笔记摘要 this 到底是什么? 排除了一些错误理解之后,我们来看看 this 到底是一种什么样的机制. 之前我们说过 thi ...

  4. Android之Http网络编程(一)

    Android应用作为一个客户端程序绝大部分都是需要进行网络请求和访问的,而http通信是一种比较常见并常用的通信方式. 在Android中http网络编程中有两种实现方式,一种是使用HttpURLC ...

  5. CocoaLumberjack+XcodeColor(输出带有颜色的日志)在安装过程中遇到的问题

    在安装的时候遇到了各种坑,(在这里用到的pch文件的使用以及解决无法引入的问题,可以参考上午的文章) 一(XcodeColor的安装).在github上下载XcodeClolor的插件,并且安装,Xc ...

  6. oc 一些通用函数

    1 i= 0,1,2... unichar c = [self characterAtIndex:i]; //取出i这个位置对应的字符 2 拼凑字符串 [NSString stringWithForm ...

  7. TortoiseSVN本地代码版本控制设置步骤。

    1.下载安装TortoiseSVN客户端. 2.在某个盘创建空的文件夹作为项目代码的版本库.在空的文件夹内部右键鼠标TortoiseSVN->Create repository here 3.在 ...

  8. CentOS配置java运行环境

    CentOS_配置_docker CentOS_6.5 1.CentOS_6.5在安装docker-io之前需要首先卸载docker包(没下载过可以省略) $ sudo yum -y remove d ...

  9. sgu 107 987654321 problem

    其实挺水的,因为两个数平方,只有固定的后面几位数会影响到最后结果的后面几位数.也就是说,如果想在平方之后尾数为987654321,那么就有固定的几个尾数在平方后会是这个数,打个表,发现 10^8 内 ...

  10. Android - 安装 windows 7 安装 Android SDK 的时候出现的问题!(Connection to https://dl-ssl.google.com refused)

    Android - 安装 windows 7  安装 Android SDK 的时候出现的问题! 首先看到 Connection to https://dl-ssl.google.com refuse ...