#!/usr/bin/env python3from functools Import partialfrom itertools import repeatfrom multiprocessing import Pool, freeze_s Upportdef func (A, B): return a + bdef main (): A_args = [] 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 = Nif __name__== "__main__": freeze_support () main ()
The original view here: Https://stackoverflow.com/questions/5442910/python-multiprocessing-pool-map-for-multiple-arguments
From functools import partialfrom itertools import repeatfrom multiprocessing import Pool, Freeze_supportdef func (A, B, c) : print (c) return a + bdef main (): A_args = [1, 2, 3] Second_arg = 1 with pool () as Pool: # L = PO Ol.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 ()
Use of the starmap of the Python process pools pool