3

I am trying to run a Jupyter Notebook in the background. I found this question that included the command

jupyter notebook &> /dev/null &

which worked on my local machine. However, I have two problems:

  1. I need a token in order to be able to access my notebooks in a browser window. However, with the above command, there is no output into the Terminal window except for the process ID, and therefore I could not access my notebooks.

  2. I also need to run the notebook in the background on a remote machine. I ssh into the remote machine, and then run jupyter notebook --no-browser. However, once I close my laptop, the notebook process is killed in my local Terminal window, as well as the ssh.

I was able to crudely circumvent the above problems by running the normal

jupyter notebook --no-browser

in the remote server, and then killing the ssh to the remote server. My question boils down to the following two sub-questions:

  1. Is there any way of doing this besides closing the ssh? I guess this isn't really the biggest problem, but it seems very hacky to simply kill the ssh instead of some more elegant or more effective solution.

  2. How would I achieve the same thing on my local machine? I need to run the Jupyter Notebook in the background while also somehow getting the output. Can I direct the output into another file or read it somewhere else?

victor
  • 1,573
  • 11
  • 23

2 Answers2

4
  1. Generate a password for your Jupyter Notebook server so that you don't need to enter it via token (which will be changed each time you restart the server).

  2. Run your Jupyter Notebook server in a screen or a tmux, thus each time you close the connection with the remote server, you just detach from the screen. It will keep on running in your remote server. Next time you want to access to it, just tap in screen -r to attach the screen after you ssh to the remote server.

Hou Lu
  • 3,012
  • 2
  • 16
  • 23
1

Run the Jupyter notebook on tmux with no-browser option. And take the browser when you want it. To keep the running session like variables and all, you can make use of nbconvert in Jupyter, use the command : jupyter nbconvert --to notebook --execute --inplace mynotebook.ipynb to get the outputs on Jupyter notebook when you open it on browser after detaching several times.

Fabich
  • 2,768
  • 3
  • 30
  • 44