赞
踩
使用原生的可以参考博客:
python multiprocessing多进程执行for循环的代码:https://blog.csdn.net/weixin_35757704/article/details/118799165
def add(a: int, b: int):
return a + b
if __name__ == '__main__':
for i in range(300):
add(i, i + 1)
from joblib import Parallel, delayed
def add(a: int, b: int):
return a + b
if __name__ == '__main__':
tasks = []
for i in range(300):
tasks.append(delayed(add)(i, i + 1))
multi_work = Parallel(n_jobs=2, backend='multiprocessing')
res = multi_work(tasks)
print(res)
学习joblib
可以参考:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。