You can use this Jupyter extension

Background image by Free-Photos from Pixabay

By default, a Jupyter Notebook saves your work every 2 minutes, and if you want to change this time interval you can do so by using the %autosave n magic command; where n is the number of seconds, and if n=0 this means no autosaving.

But the %autosave magic command produces effects only inside the notebook in which this command is run, and only in that particular session. If you shut down the notebook and re-open it you have to run the %autosave command again, or if you open another notebook, also you have to run the command again.

So, wouldn’t it be nice if there were a way to make this setting global, and not have to run the %autosave command over and over again?

Well… there is a solution. The autosavetime Jupyter extension. This extension allows us to set the autosave interval globally either by using a GUI widget or by setting some parameters in this extension’s JS file.

Let’s start by installing it.

Installation

Firstly, we need to install the jupyter_contrib_nbextensions python package. This package will then be used to install the extensions and to activate/deactivate a certain extension.

pip install jupyter_contrib_nbextensions

Then, we need to install the extensions themselves. And what this means is that we basically copy all the javascript and CSS files of all available extensions to the Jupyter data directory and then edit the relevant config files. In Windows, the folder in which these extensions are copied is %APPDATA%\jupyter, in Linux is ~/.local/share/jupyter, and in Mac is ~/Library/Jupyter.

Below is the command that does these things:

jupyter contrib nbextension install --user

After we installed the extensions, we need to enable the autosavetime extension. We do this by using the following command:

jupyter nbextension enable autosavetime/main

How to use it

After installation, there should appear a widget like this in the top bar of the notebook:

Now, setting the autosave time interval is as simple as choosing the appropriate option from the dropdown.

What if the value that you want is not listed in that dropdown?

Then you can change the extension’s main.js file.

Depending on your Operating System, this file should be at one of these locations:

  • Windows: %APPDATA%\jupyter\nbextensions\autosavetime\main.js
  • Linux: ~/.local/share/jupyter/nbextensions/autosavetime/main.js
  • Mac: ~/Library/Jupyter/nbextensions/autosavetime/main.js

You need to change the parameter autosavetime_set_starting_interval to true, and then autosavetime_starting_interval to whatever you want as soon as it is a valid number of minutes.

Then save the JS file and restart your notebook. Now, the changes should have taken effect.


If you want to learn Python Programming and Machine Learning, then here are two great books that can help you:

I hope you found this information useful and thanks for reading!

Let’s keep in touch! Feel free to follow me on social media: Medium, LinkedIn, Twitter, Facebook to get my latest posts.

This article is also posted on Medium here. You can have a look!


Dorian

Passionate about Data Science, AI, Programming & Math

0 0 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x