How to run jupyter notebook in the background ? No need to keep one terminal for it

后端 未结 11 2188
有刺的猬
有刺的猬 2020-12-02 10:17

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

相关标签:
11条回答
  • 2020-12-02 10:24

    You can start up the notebook in a screen or tmux session. Makes it easy to check error messages, etc.

    0 讨论(0)
  • 2020-12-02 10:26

    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 &
    
    0 讨论(0)
  • 2020-12-02 10:28

    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.

    0 讨论(0)
  • 2020-12-02 10:32

    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.

    0 讨论(0)
  • 2020-12-02 10:32

    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.

    0 讨论(0)
  • 2020-12-02 10:35

    Tmux is a good option available to run your Jupyter Notebook in the background.

    I am running my Jupyter Notebook on a google cloud platform's VM instance with OS: Ubuntu 16.0. Where

    1. I have to start SSH terminal
    2. Then run the command: jupyter-notebook --no-browser --port=5000. It will start the Jupyter Notebook on port number 5000 on that VM instance
    3. Then I open my browser and typer ip_addrees_of_my_instance:port_number which is 5000. It will open my Notebook in the browser.

    Now 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.

    Terminal Multiplexer (tmux) to Keep SSH Sessions Running in the background after ssh terminal is closed:

    1. Start the ssh terminal
    2. Type tmux. It will open a window in the same terminal.
    3. Give command to start Jupyter Notebook here. Open Notebook.

    Now if SSH terminal is closed/terminated it will keep running your notebook on the instance.

    If the connection terminated then:

    1. reconnect or open new ssh terminal. To see this notebook (which is kept running in the background) type: tmux attach command.

    Want to terminate tmux session:

    1. Close the notebook. Then type 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/

    0 讨论(0)
提交回复
热议问题