librelist archives

« back to archive

joblib can't pickle function object?

joblib can't pickle function object?

From:
Skipper Seabold
Date:
2014-03-07 @ 21:40
Apparently I have to send this e-mail twice? I'm a bit baffled by this and
am hoping to get some help to understand. I would assume in the second
example that they're in the same scope so there's no closure. I'm on joblib
0.7.1 installed using pip on python 2.7.

These work

from joblib import Parallel, delayed

def sqr(i):
    return i ** 2

Parallel(n_jobs=4)(delayed(sqr)(i) for i in range(50))

def func(x):
   return Parallel(n_jobs=4)(delayed(sqr)(i) for i in x)

func(range(50))

But this doesn't work?

def func(x):
    def sqr(i):
        return i ** 2
    return Parallel(n_jobs=4)(delayed(sqr)(i) for i in x)

func(range(50))