python multiprocessing.Pool 中map、map_async、apply、apply_async的区别
multiprocessing是python的多进程库,multiprocessing.dummy则是多线程的版本,使用都一样。
其中都有pool池的概念,进程池/线程池有共同的方法,其中方法对比如下 :
There are four choices to mapping jobs to process. Here are the differences:
Multi-args Concurrence Blocking Ordered-results
map no yes yes yes
apply yes no yes no
map_async no yes no yes
apply_async yes yes no no
In Python 3, a new function starmap can accept multiple arguments.
Note that map and map_async are called for a list of jobs in one time, but apply and apply_async can only called for one job. However, apply_async execute a job in background therefore in parallel. See examples:
# map
results = pool.map(worker, [1, 2, 3]) # apply
for x, y in [[1, 1], [2, 2]]:
results.append(pool.apply(worker, (x, y))) def collect_result(result):
results.append(result) # map_async
pool.map_async(worker, jobs, callback=collect_result) # apply_async
for x, y in [[1, 1], [2, 2]]:
pool.apply_async(worker, (x, y), callback=collect_result)
原文地址: http://blog.shenwei.me/python-multiprocessing-pool-difference-between-map-apply-map_async-apply_async/
python multiprocessing.Pool 中map、map_async、apply、apply_async的区别的更多相关文章
- Python函数式编程中map()、reduce()和filter()函数的用法
Python中map().reduce()和filter()三个函数均是应用于序列的内置函数,分别对序列进行遍历.递归计算以及过滤操作.这三个内置函数在实际使用过程中常常和“行内函数”lambda函数 ...
- python multiprocessing pool
python 本身是不是单线程这个我真心搞不懂 但是我是来吐槽的: multiprocessing.Pool(precesses = 2) 这个语句曾经让我的内存爆满,死机不解释. 在重装 pytho ...
- java中Map,List与Set的区别(转)
Set,List,Map的区别 java集合的主要分为三种类型: Set(集) List(列表) Map(映射) 要深入理解集合首先要了解下我们熟悉的数组: 数组是大小固定的,并且同一个数组只能存放类 ...
- java中Map,List与Set的区别
Set,List,Map的区别 java集合的主要分为三种类型: Set(集) List(列表) Map(映射) 要深入理解集合首先要了解下我们熟悉的数组: 数组是大小固定的,并且同一个数组只能存放类 ...
- js中 call() 和 apply() 方法的区别和用法详解
1.定义 每个函数都包含俩个非继承而来的方法:call() 和 apply() call 和 apply 可以用来重新定义函数的的执行环境,也就是 this 的指向:call 和 apply 都是 ...
- spark中map和mapPartitions算子的区别
区别: 1.map是对rdd中每一个元素进行操作 2.mapPartitions是对rdd中每个partition的迭代器进行操作 mapPartitions优点: 1.若是普通map,比如一个par ...
- Python multiprocessing
 推荐教程 官方文档 multiprocess各个模块较详细介绍 廖雪峰教程--推荐 Pool中apply, apply_async的区别联系 (推荐)python多进程的理解 multiproce ...
- python 3.6.5 map() max() lambda匿名函数
python 3.6.5 sample: map() 会根据提供的函数对指定序列做映射. 第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 functi ...
- python中multiprocessing.pool函数介绍_正在拉磨_新浪博客
python中multiprocessing.pool函数介绍_正在拉磨_新浪博客 python中multiprocessing.pool函数介绍 (2010-06-10 03:46:5 ...
随机推荐
- service 入门
https://www.cnblogs.com/keguangqiang/p/3663086.html#undefined
- C语言中%p,%u,%lu都有什么用处
%p表示输出这个指针, %d表示后面的输出类型为有符号的10进制整形, %u表示无符号10进制整型, %lu表示输出无符号长整型整数 (long unsigned)
- P2878 [USACO07JAN]保护花朵Protecting the Flowers
一个类似国王游戏的贪心 话说要是先做了这个题,国王游戏之余懵逼这么久吗? #include<iostream> #include<cstdio> #include<alg ...
- VisualSVN 4.0.10 破解版 附上破解过程
VisualSVN一般情况下使用不需要破解,可以直接使用社区授权.但是社区授权不支持域用户. 如果要再域下面使用就需要破解了. 原版的VisualSVN和破解后的DLL已打包上传(仅供学习使用) 破解 ...
- jquery 添加和删除节点
// 增加一个三和一节点 function addPanel() { // var newPanel = $('.my-panel').clone(true) var newPanel = $(&qu ...
- SqlServer中怎么删除重复的记录(表中没有id)
SqlServer中怎么删除重复的记录(表中没有id) 其实我在别的网址也查到过删除重复的记录,不知道我是我SqlServer2012版本太低还是啥原因 delete from scwhere (c# ...
- java高并发之CountDownLatch,CyclicBarrier和join
晚上打车回家,在车上看到一篇文章<22岁大学生获谷歌天价Offer,年薪千万!>,讲的是印度一个22岁大学生多次参加ACM大赛,开源多个项目,以非常牛逼的履历通过了谷歌的AI测试,斩获谷歌 ...
- Nginx无法加载.woff .eot .svg .ttf等解决办法
在Nginx的配置文件,加上以下代码即可修复该问题 location ~ \.(eot|otf|ttf|woff|svg)$ { add_header Access-Control-Allow-Ori ...
- vue笔记v-if
如果ite.type=='培训',显示第一个img, 如果ite.type=='会议',显示第二个img
- SQL tp3.2 批量更新 saveAll
/** * 批量更新数据 * @param [array] $datas [更新数据] * @param [string] $table_name [表名] */ public function sa ...