Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover a notebook emptied after kernel crash?

While working in an ipython notebook, eventually I had to Ctrl+C as the kernel seemed to be halted.

The console gave me a message like:

[NotebookApp] Kernel  shutdown: 5faa86bf-........f6 
[NotebookApp] Kernel  shutdown: 71........22 
[NotebookApp] ....

(I had three notebooks running)

But something went wrong and my notebook file.ipynb is empty (actually only the one I was actively using).

Is there a way to recover that file before it was deleted? Some place where automatically-saved o manually-saved versions are stored?

(Running python 2.7 (Anaconda) in Windows 7)

like image 536
alberto Avatar asked Dec 03 '13 16:12

alberto


People also ask

How do I rollback a Jupyter notebook?

Jupyter will save checkpoints of your notebook from time to time, and if you realize you need to revert your whole file back to an earlier version, you can do that with the “Revert to Checkpoint” button.

Where did my Jupyter notebook go?

Click on the See all notebooks link under Recent Notebooks in the right nav bar. 2. Use My Data: Just click the My Data (folder icon) in the left menu bar. Once it opens just click Back, to go up one level to /resources and you can find your Jupyter notebooks there (may need to scroll down a little).

Where are Jupyter notebook checkpoints stored?

As a side note, the checkpoint file is located within a hidden folder named . ipynb_checkpoints . This folder is located within the same folder as the initial . ipynb file.


1 Answers

If none of the above helped, I found a workaround to recover most of the changes I did since the last checkout - by simply calling this command in your notebook:

%history -g

If you want your IPython history in a plain-text file, you can export it yourself.

You can also do it for a specific filename:

%history -g -f filename 

What does -g do? – Without -g it exports the history for the current session. With -g it exports history for all sessions.

like image 79
Serendipity Avatar answered Sep 18 '22 23:09

Serendipity