[英]Run Python Multiprocessing of same function with multiple parameters
我有一个 function 说:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.