Often we run jupyter notebook
to pop up a page in browser to use notebook. However, the terminal opening the server remains there. Is there a way that we can cl
You can start up the notebook in a screen
or tmux
session. Makes it easy to check error messages, etc.
Actually, jupyter notebook &
alone is not enough, the backend will still log to your screen.
What you need is, cited from this issue
jupyter notebook > /path/to/somefileforlogging 2>&1 &
You can use screen
to run it.
screen -A -m -d -S anyscreenname jupyter notebook --no-browser
This will start jupyter in a screen and you can access screen using screen commands.
Under *nix, the best way to run a program avoiding to be terminated by closing the terminal is to use nohup (no Hang up).
To start browser after running the server use the command:
nohup jupyter notebook &
And to start the server without opening the browser use the command:
nohup jupyter notebook --no-browser &
Note that you can shut down the jupyter
server by using Quit in the upper right of the page of jupyter
.
nohup
puts as a parent of the process init(0), so it will not receive the "Hang Up" signal when the terminal is closed. All the output (standard output and standard error) are redirected to the file nohup.out
nohup
exists both as program and shell command, so if you have bash
, check man
page of bash
to read more details.
For remote machines jupyter notebook &
works fine.
However, it does not work on local machines when you close the terminal.
For local machines use tmux
.
I am running my Jupyter Notebook on a google cloud platform's VM instance with OS: Ubuntu 16.0. Where
jupyter-notebook --no-browser --port=5000
. It will start the Jupyter Notebook on port number 5000 on that VM instanceNow up to this, all is good. But wait if the connection with my SSH terminal is terminated then the Jupyter Notebook stops immediately and hence I have to re-run it once again once the ssh terminal is restarted or from new ssh terminal.
To avoid this tmux
is very good option.
tmux
) to Keep SSH Sessions Running in the background after ssh terminal is closed:tmux
. It will open a window in the same terminal. Now if SSH terminal is closed/terminated it will keep running your notebook on the instance.
If the connection terminated then:
tmux attach
command. Want to terminate tmux session:
exit
in tmux-terminal-window.
(update: If we close the notebook and use tmux detach
command: it will exit from tmux session window/terminal without terminating/stopping the tmux sessions) For more details please refer to this article: https://www.tecmint.com/keep-remote-ssh-sessions-running-after-disconnection/