Joblib在嵌套函数调用中重用并行工作程序

时间:2018-04-16 21:22:36

标签: python joblib

我正在尝试在执行嵌套函数调用时重用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?

0 个答案:

没有答案