make a jupyter notebook run even if the page is closed - jupyter-notebook

I love notebooks. I love them so much that I have many of them running at the same time, often in different browsers, sometimes on different remote clients. I miss one feature: when I close the tab corresponding to a running notebook, it warns that the corresponding run will be stopped.
My question:
How do I make a jupyter notebook resume it's run even if the page is closed ?
such that I can:
re-open the tab in another browser (possibly on a remote computer such as a tablet),
restart a browser when it needs to,
close those with long running time for later inspection.
From what I understand, the client-server architecture could make that possible, but that there may be issues with multiple concurrent runs...
PS: I created an issue on GitHub

In fact, this was answered in the github issue:
takluyver commented on 26 Apr 2017: Anything already running in the
notebook will keep running, and the kernel it started for that will
stay running - so it won't lose your variables. However, any output
produced while the notebook isn't open in a browser tab is lost; there
isn't an easy way to change this until we have the notebook server
able to track the document state, which has been on the plan for ages.
Thanks!

Related

Reconnecting to jupyter ipynb (running) files

How can I run Jupyter notebooks disconnecting/reconnecting to its kernels without losing all the output from completed cells?
I know this has been asked several times and there are plenty of Q&A and web pages speaking about this, but I could not understand whether or not what I would like to do is possible and, if it is possible, what I am doing wrong. Many web pages and questions date back to several years ago, so, may be, such a basic functionality has been finally implemented.
I set up a remote jupyter using screen/tmux and ssh port forwarding. So I am able to connect to the remote machine using a web browser.
This is the notebook I run:
cell 1
import time
i = 0
while i < 10:
i += 1
print(i, flush=True)
time.sleep(5)
print("done")
cell 2:
print(i)
When I run the first cell, close the browser, reconnect to the kernel running the notebook above (Jupyter -> Running -> notebook) it seems that nothing is running. However, when I run the second cell, I realize the kernel is still running the first cell: there is no output for a while, then 10 is printed.
But:
When I reopen the notebook, there is no indication about which cell is currently running;
The output is lost. Not only the output produced after disconnecting from the kernel (closing the browser tab), but also all the output produced by the running cell between the save action and the disconnection.
This makes Jupyter completely useless when running (long) notebooks whose output needs to be monitored every once in a while.
I have this question. Without using tricks (like capturing output with some magic, writing the output to external log files, running the notebook as a python script, ...), is it possible to configure jupyter in order to disconnect/reconnect from/to its kernels running ipynb files using only the web interface and keeping the output produced while no browsers were attached to it?

'_xsrf' argument missing from POST - Need a Permanent Fix - Other Suggested Solutions are Not Working

Every time I open Jupyter Lab from Anaconda, I receive the following error: '_xsrf' argument missing from POST.
I am using Google Chrome on Windows 10.
I've followed the suggestions from the other posts, e.g. copy and paste the URL into different Chrome tab and refresh the page.
It seems like my sessions are not properly closing, even if I terminate all kernels for that specific session.
I've closed all Jupyter Lab sessions by using jupyter notebook stop <session_number>. Nothing has changed.
Someone has suggested revising the configuration. However, I am unclear as to what problems a reconfiguration will cause downstream.
One last thing, I do NOT encounter this problem when running Jupyter Notebook. The error only occurs when I open Jupyter Lab.

Jupyter Lab, R kernel - Wanted: to prevent Jupyter from opening the R help server

Unfortunately, I made a change to the Jupyter Lab settings recently. Jupyter had never been able to access the remote R help server. Usually this was never an issue because most help files are displayed in Jupyter. The way help is called on a function or method is typing: ?question. The "question" being the name of an R function or method. Ex. ?plot
Infrequently one of the R packages will not list its help in Jupyter and instead try to open the remote R help server. This has never worked in the past. The tab for a remote server never opened. This has never really been an issue until recently. Recently I decided to "fix" this issue and spent a good deal of time looking up the solution. I made this "fix" and Jupyter began working properly to open the remote R help server. But the fix is a problem that is way too obnoxious.
Each time I type the question mark in Jupyter, Jupyter causes the browser to open a new tab for the remote R help server. It is impossible to type fast enough after typing typing the ?. Once the ? is typed, the typing is interupted while the browser opens a new R server help website. As soon as returning to the typing, another browser tab opens and interrupts the typing .
It is impossible to finish typing the name of a function after the ? without having multiple interruptions to the typing while multiple new windows are opened in the browser at the R help server website. By the time I've finished typing: ?ppp, there will the 5 interruptions and new browser tabs opened. If I typed slowly, there may be 10 - 12 interruptions and 10 new tabs opened at the R help server.
How to prevent Jupyter from trying to access the remote R help server every time the ? is typed when looking up a description of a function? How to get back to that happy place I had before I'd made whatever change that caused this nightmare to happen?
Solved my own question.
This issue had nothing to do with R. I assumed I had changed a configuration in R, but that was not the case. This was an issue I had caused when I had changed a setting in Jupyter lab.
I can say with certainty this issue was definitely caused when I changed the "Contextual Help" setting under the Commands tab in Jupyter. This setting is related to the Contextual Help selection found under the Help tab. And this setting was causing multiple R help server tabs to open in the browser after I typed: ?
Upon rediscovering this Jupyter setting today I recalling that I had been down this path before. I selected "Contextual Help". Jupyter auto restarted and the issue went away. I can gladly say that I can perform search again for the description of an R function: Ex ?plot ,and receive the description of this function within Jupyter the same as before. I no longer have the issue of the browser opening or multiple new tabs at the remote R help server after typing ?

Reconnecting to jupyter notebook loses output

I have a remote server with a long-running jupyter notebook process (keras training).
When I reconnect to the notebook (either by reloading the chrome tab or by clicking on the notebook in the list of running notebooks), I get a tab marked as "running" (hourglass icon instead of the book icon), and I can confirm that the process is running by ssh to the server.
However, the progress indicator and stdout of the process running is lost. The bar
71255/225127 [========>.....................] - ETA: 3:32:43 - loss: 2.1890
is never updated. Other (non-keras) processes lose their stdout (unless I also write to a file).
Is this a known problem?
Is there a way to recover the output stream after reconnecting?
This is a known problem, and as far as I know IPython has already published a collaboration jupyter notebook option, that they said "could solve the problem in the collaboration mode"
Sadly, if it's lost, there's no way to find it back (unless you outputted to a file or to a variable, or you know how to do some intricate tricks that could recover the data)
One way to solve this, to prevent the issue in advance, is to use magic code
%%capture <VARIABLE NAME> in the cell you want to save the stdout when closed the notebook in your browser (don't terminate your notebook). In this way, output will be save in <VARIABLE NAME> and later on you can access it using print(<VARIABLE NAME>.stdout), after the process is finished.

RStudio Server on Microsoft Azure instance

I am currently running R on a Microsoft Azure instance (Ubuntu virtual machine) using RStudio as my IDE, to which I connect simply through my browser. I am trying to run some commands that take quite some time to complete from within RStudio and figured that I could simply close my tab with RStudio open and the process would keep running. However, when I try to reconnect to see how the process is doing, the page keeps loading but I am unable to see RStudio.
I have a few questions regarding running RStudio on a server:
First, am I correct in thinking that I can close my tab and keep the process running?
Second, is it normal behaviour that I am unable to connect to the server while the process is running?
Third, am I going about this the correct way or are there better ways?
Yes, you can close your tab and keep it running.
RStudio Server waits on updates from the R process to update the UI. This means that if you have a long-running computation, your tab may not fully reload until it's finished. You may also have seen this in the middle of a session: when R is busy, you can have problems saving scripts that are open in the editor pane.
Logging out in the middle of a computation should be safe, but be aware that RStudio will save your workspace and shut R down after a period of inactivity. It then reloads everything when you log back in. But this only extends to objects in memory; if you have any files saved in your temp directory, they'll have disappeared when you come back. They're probably still on the disk, but since your new R session has a new temp directory, you'll have to do a manual search for them.

Resources