2

我想并行化一个用 joblib.Memory 缓存的函数,但是我收到以下错误:

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))
4

1 回答 1

2

尝试为装饰函数使用不同的名称,例如foo_cached = mem.cache(foo)代替装饰器。另见https://github.com/joblib/joblib/issues/226

于 2016-07-19T21:56:35.670 回答