还有更加简写的方法,也是通常见到的方式:
from joblib import Parallel, delayed
def add_func(x, y):
return x + y
if __name__ == '__main__':
x_list = [1, 2, 3] # 参数x列表
y_list = [4, 5, 6] # 参数y列表
res = Parallel(n_jobs=2, backend='threading')([delayed(add_func)(x, y) for x, y in zip(x_list, y_list)])
print(res) # 打印结果