Skip to content

Commit

Permalink
BUG: pickling MemoizeFunc does not store timestamp
Browse files Browse the repository at this point in the history
Rather than using __getstate__ to override pickle, we use reduce, to
make sure that the __init__ is called at unpickle time, in order to
create the directory needed.
  • Loading branch information
GaelVaroquaux committed Mar 31, 2011
1 parent ea1a2d6 commit 53da2dc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion joblib/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class JobLibCollisionWarning(UserWarning):


################################################################################
# class `Memory`
# class `MemorizedFunc`
################################################################################
class MemorizedFunc(Logger):
""" Callable object decorating a function for caching its return value
Expand Down Expand Up @@ -182,6 +182,15 @@ def __call__(self, *args, **kwargs):
shutil.rmtree(output_dir, ignore_errors=True)
return self.call(*args, **kwargs)


def __reduce__(self):
""" We don't store the timestamp when pickling, to avoid the hash
depending from it.
In addition, when unpickling, we run the __init__
"""
return (self.__class__, (self.func, self.cachedir, self.ignore,
self.save_npy, self.mmap_mode, self._verbose))

#-------------------------------------------------------------------------
# Private interface
#-------------------------------------------------------------------------
Expand Down

0 comments on commit 53da2dc

Please sign in to comment.