joblib/joblib — Issue #14: instance method caching does not work when executed through ipython
Author: otizonaizit
Created: 2011-11-16 14:46:03+00:00
State: open

consider the following code (taken almost verbatim from the docs):
```python
import joblib
mem = joblib.Memory(cachedir='/tmp/joblib')

class Foo(object):
def __init__(self):
self.method = mem.cache(self.method)
def method(self, x):
pass

foo = Foo()
foo.method(42)
```

save it to a file called joblib_bug.py. If you run it through the standard python interpreter, it works.
if you run it thourhg ipython, you get:
```bash
ipython joblib_bug.py
------------------------------------------------------------
Traceback (most recent call last):
File "joblib_bug.py", line 11, in
foo.method(42)
File "/usr/lib/pymodules/python2.7/joblib/memory.py", line 162, in __call__
output_dir, _ = self.get_output_dir(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/joblib/memory.py", line 224, in get_output_dir
coerce_mmap=coerce_mmap)
File "/usr/lib/pymodules/python2.7/joblib/hashing.py", line 116, in hash
return hasher.hash(obj)
File "/usr/lib/pymodules/python2.7/joblib/hashing.py", line 29, in hash
self.dump(obj)
File "/usr/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/lib/pymodules/python2.7/joblib/hashing.py", line 43, in save
pickle.Pickler.save(self, obj)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.7/pickle.py", line 681, in _batch_setitems
save(v)
File "/usr/lib/pymodules/python2.7/joblib/hashing.py", line 43, in save
pickle.Pickler.save(self, obj)
File "/usr/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.7/pickle.py", line 396, in save_reduce
save(cls)
File "/usr/lib/pymodules/python2.7/joblib/hashing.py", line 43, in save
pickle.Pickler.save(self, obj)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 748, in save_global
(obj, module, name))
PicklingError: Can't pickle : it's not found as __main__.Foo

WARNING: Failure executing file:
```

I have no idea what this means. it is most probably not a bug in joblib, but maybe you know what's wrong with ipython.

ciao,
tiziano