我正在尝试在执行嵌套函数调用时重用worker。这是场景......
from joblib import Parallel, delayed
def func1():
with Parallel(n_jobs = -1) as parallel:
var1 = parallel(delayed(func2)(i) for i in range(5))
print(var1)
def func2(i):
var2 = parallel(delayed(func3)(x, i) for x in range(5))
return var2
def func3(x, i):
return x+i
if __name__ == '__main__':
func1()
我在func2()
中收到错误,parallel
未定义。如何为这种嵌套循环使用上下文管理器API?