Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I autosave a running jupyter python notebook without having it open in a browser tab?

So I have a long-running python notebook.

As long as it's open in my browser's tab, it's autosaving every 2 minutes, and life is good.

Is it possible to keep it auto-saving even if I close the browser tab?

The kernel already keeps running when I close the tab, which is great.

This is kind of like "screen", but in jupyter

EDIT: Even if I leave the tab open in my browser, I noticed that after 24 hours, the "kernel status" in the top right becomes "disconnected", even though the running cell still has output being piped to it from the server websocket connection

like image 433
Shadi Avatar asked Aug 21 '17 05:08

Shadi


People also ask

How do I save my Jupyter notebook automatically?

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.

How do I keep the Jupyter notebook running after closing the browser tab?

This can be done by typing jupyter notebook in the terminal, which will open a browser. Then, navigate to the respective jupyter notebook file in the browser and open it. Click Cell > Run All on the toolbar. All done!

How do I save my Jupyter notebook locally?

Saving a Jupter notebook Saving your edits is simple. There is a disk icon in the upper left of the Jupyter tool bar. Click the save icon and your notebook edits are saved.

Can you run Jupyter notebook without browser?

Step 1: Run Jupyter Notebook from remote machine Log-in to your remote machine the usual way you do. In most cases, this is simply done via an ssh command. Once the console shows, type the following: remoteuser@remotehost: jupyter notebook --no-browser --port=XXXX # Note: Change XXXX to the port of your choice.


1 Answers

No, you can't (for now), and their will be no point in doing it. The reason is, as soon as you close your tab, some critical information is lost because it is in the memory of the Javascript VM that run the page.

Any update sent by the kernel after you've closed your page are lost.For example try the following.

  • create a cell with sleep(10);print('Hello')
  • Execute the cell
  • Quickly close and reopen the tab.
  • the "Hello" will never be printed.

The mapping between the "Execution request" and the "Execution reply" have been lost, and can't be recovered.

The Jupyter team is aware of that. The fixes are not that hard, but require a lot of careful refactor and API design. There was a long in person discussion in NYC at the end of August 2017. Right now the focus is to polish JupyterLab, and once this is done it will be one of the area of focus. It will go hand in hand with real-time collaboration.

In more detail, the fix requires to "move" the notebook model from the client (your browser) to a server side (what is serverside is handwaved for now, but here is not the place to expand it), there are technical questions about that, like what to do with widgets, and when collaborating what state is shared by everyone and what state is per-client. Like if you fold some code, should this be stored ? or not ?

If you are interested in that, I would suggest getting involved with JupyterLab, there will be soon a number of low hanging fruits to contribute that should quickly fix 80% of the usecases.

like image 137
Matt Avatar answered Oct 21 '22 12:10

Matt