Skip to content

Instantly share code, notes, and snippets.

@J535D165
Forked from 33eyes/jupyter_notebook_w_nohup.md
Created August 12, 2019 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save J535D165/0e840291e7b2598ec157e13e9b9ca569 to your computer and use it in GitHub Desktop.
Save J535D165/0e840291e7b2598ec157e13e9b9ca569 to your computer and use it in GitHub Desktop.
Jupyter notebook with nohup

Running jupyter notebook with nohup

This is helpful when running jupyter notebook on remote server (AWS) and tunneling into it, because with nohup the notebook process continues to run on the server even if you get disconnected from it (any running notebook code continues to run on the server without interruption, and just needs to be re-tunneled into).

Start jupyter notebook on remote server

In the remote server terminal, run:

nohup jupyter notebook &

(the & sends the process to run in the background, so that the terminal window can be used)

Tunnel into the remote jupyter notebook from local

In the local terminal, run:

ssh awsgpu -NL 8157:localhost:8888 ubuntu@11.111.111.11

replacing awsgpu with remote server ssh login, 8157 with a free local port, 8888 with the port used by jupyter notebook on the remote server (usually it's 8888), and 11.111.111.11 with remote server IP.

Stop the remote jupyter notebook

Since we now have a jupyter notebook running in the background, we can't stop the notebook by closing the terminal window or Ctrl C. Here are the steps to stop it.

  • check what jupyter notebooks are running:
jupyter notebook list

(note which ports are being used)

  • find which process IDs (PIDs) are being run on the port used by the jupyter notebook(s):
netstat -tulpn

Look for processes that are running on port 8888 (or whichever port was listed in the step above), and note the PID.

  • now kill the process(es):
kill 2759

replace 2759 with the PID from the step above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment