Crispy13
Crispy13

Reputation: 369

Jupyter how to run cells on background?

Usually, if the network connection is lost or the web browser is closed while cells are running i have to run cells again from the beginning.

To deal with this i converted .ipynb to .py and used 'nohup python .py'

Is there any way to prevent running cells from stopping like nohup?

Thank you in advance.

Upvotes: 5

Views: 14129

Answers (4)

Sam Mason
Sam Mason

Reputation: 16184

the code still runs, just the standard output/error gets lost. for example, if I have a cell containing:

from time import sleep
sleep(5)
42

and I save the notebook, run this cell, close the browser tab, wait 5 seconds, and then reopen the tab, I can run:

Out

(this is the variable where results of running cells ends up) I see:

{1: 42}

i.e. the code ran to completion

Upvotes: 1

Jay
Jay

Reputation: 824

According to https://github.com/jupyter/notebook/issues/2446

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.

When you close tab it does not mean the process was ended, it keeps running background without output.

I am not sure if there is any way to achieve this now, but I found that if you are using jupyterhub, you can continue run ipython a terminal tab, when the tab was closed or switch to another device (close previous web page), all output reserved. Maybe screen or tmux is better?

Upvotes: 5

Kshitij Saxena
Kshitij Saxena

Reputation: 940

You can start your process in a different thread.

def network_call():
    # Do something here

threading.Thread(target=network_call).start()

move_ahead()

Upvotes: 7

WOET
WOET

Reputation: 25

For my case:

jupyter --version
4.4.0
jupyter notebook --version
5.7.4

I run a jupyter notebook in a server, and connect to it using my laptop. Even if the connection loses or the browser is close, the running cells won't be stopped. File downloading process running in terminal won't be influenced, either.

May I know more about your situation?

Such as which version do you use, and where do you run your jupyter notebook, in local or on a server?

Upvotes: 0

Related Questions