我想对用joblib.Memory缓存的函数进行Parallellize
但是我得到以下错误:
TypeError: can't pickle function objects
这是代码:
import joblib
mem = joblib.Memory(cachedir='/tmp')
@mem.cache
def foo(x):
# do some complicated task
return x + 1
if __name__ == '__main__':
f = joblib.delayed(foo)
res = joblib.Parallel(n_jobs=-2)(f(x) for x in range(100))
最佳答案
尝试对装饰函数(例如foo_cached = mem.cache(foo)
)使用不同的名称,而不是装饰器。另见https://github.com/joblib/joblib/issues/226
关于python - 如何使用joblib并行化缓存的函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38465445/