python利用multiprocessing库的Pool.map快速建立多线程,并使用多参数
from multiprocessing import Pool def cal(item): n, mod = item res = 1 for i in range(2, n+1): res = res * i % mod return res if __name__ == "__main__": args = [] for i in range(1, 10): args.append((i,1000000007)) with Pool(10) as pool: results = pool.map(cal, args) print(results)
运行结果:
[1, 2, 6, 24, 120, 720, 5040, 40320, 362880]