#!/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()

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2022-12-23
  • 2021-09-23
  • 2021-12-13
  • 2022-01-05
猜你喜欢
  • 2022-01-06
  • 2021-11-23
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案