Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is it possible to make a jupyter notebook run even if the page is closed? #2446

Closed
laurentperrinet opened this issue Apr 26, 2017 · 13 comments
Closed

Comments

@laurentperrinet
Copy link

I am running multiple notebooks at the same time, often in different browsers, sometimes on different remote clients. till now, 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 ?

From what I understand, the client-server architecture could make that possible, but that there may be issues with multiple concurrent runs...

PS: I also asked the question on SO and will make sure to make this issue updated if I get solutions.

@takluyver
Copy link
Member

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.

@dniku
Copy link

dniku commented Aug 4, 2018

Dupe of #1647?

@abalter
Copy link

abalter commented Sep 25, 2018

@takluyver -- I have verified that the notebook keeps running in the background with:

from time import sleep
file = open("jupyter_tab_close_test", "w")
file.close()
i = 0
while True:
    print("{}\n".format(i))
    i +=1
    with open("jupyter_tab_close_test", "a") as f:
        f.write("{}\n".format(i))
    sleep(1)

When I tail -f the file the output keeps coming after I close the tab.

I had an idea for how to at least keep output to stdout, but it does not work, and I don't understand why.

  1. Select code to run
  2. "Run Selected Text or Current Line in Console"
  3. Close tab
  4. Open tab
  5. Open console for notebook

I would expect to see the output pick up where it left off being written to the console. I don't see that.

@chenqiuyuan
Copy link

@takluyver Is the problem handled? If not, maybe we can redirect the output into a file so that it is available in a different console. But how could it be easy to achieve (write as little code as possible)?

@takluyver
Copy link
Member

There is a kind of interim fix in place: when the browser disconnects, the server should now buffer output messages until the browser reconnects, and then send them through.

@carlthome
Copy link

Great news!

@boehle
Copy link

boehle commented May 28, 2019

There is a kind of interim fix in place: when the browser disconnects, the server should now buffer output messages until the browser reconnects, and then send them through.

How does that work in practice. How do I disconnect my browser from the session other than closing the tab?

@takluyver
Copy link
Member

Closing the tab is the only explicit way to do it, as far as I'm aware. It may also happen if network issues mean the server can't send output to your browser.

In either case, some outputs may be lost if they're sent before it detects that the websocket is disconnected.

@boehle
Copy link

boehle commented May 28, 2019

@takluyver alright thanks :). I'll give it a try.
Otherwise someone said over here that you can just run some other cell after a disconnect and reconnect to get all the output.
Or is this what you've been referring to?

@takluyver
Copy link
Member

Maybe. That person seems to be using Google Colab, though, so it might be a bit different.

@monghimng
Copy link

Simple fix could be instead of just using the built-in print, redefine it and save it to a temporary string. Then you can access the notebook again, examine that string instead. Of course we have to be care the string doesn't get ridiculously large.

@drmatthewclark
Copy link

just log output to a file so you can see it later - e.g. something like

"""
message writer. log to file
"""
def message( msg ):

data = str(datetime.datetime.now()) + "  " + msg
print(data)
with open(status_file, 'a') as sfile:
    if msg[-1] != '\n':
        msg += '\n'
    sfile.write(data)

@tonyfast
Copy link
Collaborator

This is being solved in JupyterLab and will be solved in the future Notebook v7 release.

For more information about this new release, checkout the Notebook v7 Enhancement Proposal.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants