码迷,mamicode.com
首页 > 编程语言 > 详细

python进程池pool的starmap的使用

时间:2018-05-17 11:52:17      阅读:2200      评论:0      收藏:0      [点我收藏+]

标签:ssi   env   print   name   question   itertools   tool   pool   too   

#!/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进程池pool的starmap的使用

标签:ssi   env   print   name   question   itertools   tool   pool   too   

原文地址:https://www.cnblogs.com/c-x-a/p/9049266.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!