运行 Python 具有多个参数的同一函数的多重处理

Run Python Multiprocessing of same function with multiple parameters

我有一个函数说:

 Fun1(a,b):
   return a*b

我想用不同的 a 和 b 值多次调用 Fun1。 需要使用多处理,因为 Fun1 在

中被调用了数百万次
from concurrent.futures import ProcessPoolExecutor


def fun1(a, b):
    return a * b

# if __name__ == '__main__': is required for platforms that do not
# support fork(), such as Windows:
if __name__ == '__main__':
    a = [1, 2, 3]
    b = [4, 5, 6]
    with ProcessPoolExecutor(max_workers = 3) as executor:
        results = executor.map(fun1, a, b)
    for result in results:
        print(result)
4
10
18