python进程池pool的starmap的使用
2018-05-17 09:11
826 查看
#!/usr/bin/env python3 from functools import partial from itertools import repeat from multiprocessing import Pool, freeze_support def func(a, b): return a + b def main(): a_args = [1,2,3] second_arg = 1 with Pool() as pool: L = pool.starmap(func, [(1, 1), (2, 1), (3, 1)]) M = pool.starmap(func, zip(a_args, repeat(second_arg))) N = pool.map(partial(func, b=second_arg), a_args) assert L == M == N if __name__=="__main__": freeze_support() main()
原文看这里:https://stackoverflow.com/questions/5442910/python-multiprocessing-pool-map-for-multiple-arguments
from functools import partial from itertools import repeat from multiprocessing import Pool, freeze_support def func(a, b, c): print(c) return a + b def main(): a_args = [1, 2, 3] second_arg = 1 with Pool() as pool: # L = pool.starmap(func, [(1, 1), (2, 1), (3, 1)]) # M = pool.starmap(func, zip(a_args, repeat(second_arg))) N = pool.map(partial(func, b=second_arg,c="124"), a_args) if __name__ == "__main__": freeze_support() main()
相关文章推荐
- python 进程池1 - Pool使用简介
- python 进程池1 - Pool使用简介
- Python多进程并发操作中进程池Pool的应用
- python进程池:multiprocessing.pool
- Python 多进程并发操作中进程池Pool
- python并行化介绍及使用 Pool
- python 进程池Pool
- 解决python进程池中无法使用multiprocessing.Queue
- python进程池:multiprocessing.pool
- Python多进程并发操作中进程池Pool的应用
- Python多进程并发操作中进程池Pool的应用
- python 线程池threadpool(使用篇)
- python线程池(threadpool)模块使用
- python 进程池pool简单实例
- Python 使用进程池下载视频
- python线程池(threadpool)模块使用
- 如何使用键盘中断处理Python进程池
- python进程池:multiprocessing.pool
- python线程池(threadpool)模块使用
- python进程池:multiprocessing.pool