Saving/Restoring a Jupyter Notebook Session
Published in
Oct 27, 2020
Originally published at http://www.ds4n6.io.
Say you have been working a lot in your current notebook, you have lots of DataFrames and Series that get a long time to be computed, and you want to make sure you recover quickly if, for some reason, your Session (Kernel) dies.
The answer is “dill”.
Installation:
pip install dill
Save a Notebook session:
import dill dill.dump_session('notebook_env.db')
Restore a Notebook session:
import dill dill.load_session('notebook_env.db')
Caveats:
- Fails when there are generators.
- If you have pyodbc connection objects hanging around, you’ll need to close them and then set them all to None otherwise, you get a “TypeError: can’t pickle pyodbc.Connection objects” error.
- The notebook state does not include graphs that were generated by your code, so you’ll need to rerun the cells to bring these back.
Refs: