dill.load_session Fails
grach0v opened this issue · comments
I tried to save and load session using dill.
import dill
dill.dump_session('stage1.db')
restart computer
import dill
dill.load_session('stage1.db')
but it gives me an error
TypeError Traceback (most recent call last)
Cell In[1], line 2
1 import dill
----> 2 dill.load_session('stage1.db')
File [c:\Users\justw\miniconda3\envs\dsenv\lib\site-packages\dill\session.py:489](file:///C:/Users/justw/miniconda3/envs/dsenv/lib/site-packages/dill/session.py:489), in load_session(filename, main, **kwds)
487 def load_session(filename=str(TEMPDIR/'session.pkl'), main=None, **kwds):
488 warnings.warn("load_session() has been renamed load_module().", PendingDeprecationWarning)
--> 489 load_module(filename, module=main, **kwds)
File [c:\Users\justw\miniconda3\envs\dsenv\lib\site-packages\dill\session.py:471](file:///C:/Users/justw/miniconda3/envs/dsenv/lib/site-packages/dill/session.py:471), in load_module(filename, module, **kwds)
468 runtime_main = '__runtime__.%s' % main.__name__
469 sys.modules[runtime_main] = main
--> 471 loaded = unpickler.load()
472 finally:
473 if not hasattr(filename, 'read'): # if newly opened file
File [c:\Users\justw\miniconda3\envs\dsenv\lib\site-packages\dill\_dill.py:419](file:///C:/Users/justw/miniconda3/envs/dsenv/lib/site-packages/dill/_dill.py:419), in Unpickler.load(self)
418 def load(self): #NOTE: if settings change, need to update attributes
--> 419 obj = StockUnpickler.load(self)
420 if type(obj).__module__ == getattr(_main_module, '__name__', '__main__'):
421 if not self._ignore:
422 # point obj class to main
TypeError: Template.__new__() missing 1 required positional argument: 'source'
dill
vesrion is 0.3.6
Python 3.10.11
Windows
I'm not getting the same thing as you (however, I'm testing on a Mac):
Python 3.10.11 (main, Apr 8 2023, 00:55:46) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> dill.__version__
'0.3.6'
>>> foo = lambda x:x*x
>>> bar = 4
>>> dill.dump_session('stage1.db')
>>>
dude>$ python
Python 3.10.11 (main, Apr 8 2023, 00:55:46) [Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> dill.load_session('stage1.db')
>>> foo(bar)
16
>>>
Are you seeing the same error in all cases, or is there something in particular that triggers the error? If so, please provide a minimal test case the reproduces what you are seeing.
From the traceback, it seems like some object pickled, but failed to load.
Hm.
I have tried your example and it did work.
In my case there is a big jupyter notebook, so I will try to get the smallest example when it fails and post it here.
This confirms that you have an unpickleable object in your notebook, or more specifically, an object that fails upon deserialization (e.g. load).
Is there a way to make some kind of verbose load_session, so I can understand what object fails?