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

可紊 提交于 2019-12-13 11:59:07

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/45789906/can-i-autosave-a-running-jupyter-python-notebook-without-having-it-open-in-a-bro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!