4

I run a jupyter notebook in the background on a Mac using

>jupyter notebook &

Because it is running in the background I can't use use ctrl-c to kill it. Furthermore no processes seem to have the name jupyter in the activity monitor.

This github issue suggests that this no way to do it from the browser: https://github.com/jupyter/notebook/issues/1530 however it says it should be possible to do from the command line using jupyter notebook stop <portno> but that does not seem to work for me.

How do I shutdown the jupyter server (ideally without having to search for the pid and then invoking kill)?

patapouf_ai
  • 17,605
  • 13
  • 92
  • 132
  • In a terminal use `ps aux` to view all running processes. If it is not in this list, it is not running. Then use `kill` with the PID of the process. – Matt Clark Sep 20 '17 at 17:18
  • I can't even find the pid because no processes are named jupyter as mentionned. But in any case, I would like a more elegant way if possible. – patapouf_ai Sep 20 '17 at 17:19
  • If there are no processes named jupyter, then jupyter isn't running. I don't know what sort of answer you were expecting, in terms of "more elegant". – juanpa.arrivillaga Sep 20 '17 at 17:23
  • It is most definitely running because I can still access from the browser. – patapouf_ai Sep 20 '17 at 17:24
  • do `ps aux | grep jupyter` does it return anything? – juanpa.arrivillaga Sep 20 '17 at 17:25
  • right, interestingly the process isn't named jupyter but it can be found using `ps` because the launch command contains jupyter. – patapouf_ai Sep 20 '17 at 17:30
  • What do you mean? Do you mean it's not showing up as "process name" in MacOS Activity Monitor? Don't use that. Use *the shell*. – juanpa.arrivillaga Sep 20 '17 at 17:32
  • That is what I meant indeed. – patapouf_ai Sep 20 '17 at 17:34
  • 1
    Also, you can always use `jobs` to see running background jobs. Then, use `fg` to put the job back in the *foreground*, and then you can use ctrl-c. If there are more than one, there will be a number, e.g. `[2]+ Running jupyter notebook &` then you use the number, e.g. `fg 2`, or just kill it directly `kill %2` – juanpa.arrivillaga Sep 20 '17 at 17:35
  • @juanpa.arrivillaga Thank you! That is the best answer for me so far. – patapouf_ai Sep 20 '17 at 17:41

6 Answers6

12

Starting from jupyter notebook version 5.1.0, the command

jupyter notebook stop <port number>

should shutdown the notebook server. If you don't enter a port, it defaults to 8888 as that is the default. To know on which ports the servers are currently running, you can do

jupyter notebook list

With jupyter notebook version 5.0, if it is running in the background of your terminal a solution is to do as @juanpa.arrivillaga wrote in the comments:

jobs

to see the jobs running in the background if there is only one and it is the jupyter notebook then

fg

will bring it back to the foreground at which point you can kill it with ctrl-c. And if there are many processes in the background, for example, jobs returns

[1] Running firefox &

[2] Running jupyter notebook &

[3] Running python calc.py &

then fg 2 brings the wanted process back to the foreground to be able to kill it with ctrl-c, or in one step kill %2.

patapouf_ai
  • 17,605
  • 13
  • 92
  • 132
3

In a terminal you could run

pkill -f -1 jupyter*

Or I have found this to work when all else fails

sudo pkill -1 -f python

Harry
  • 2,965
  • 1
  • 13
  • 19
0

Use kill -9 or kill -2 command. To find id of your process use ps aux.

Anton Hulikau
  • 336
  • 1
  • 3
  • 7
0

Had this issue when running in the background on an EC2, rebooting fixed the issue

Ryan Charmley
  • 1,127
  • 15
  • 18
0

On mac terminal after running jupyter notebook it says

Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

I've tried it - it works for me.

0

To stop jupyter lab for which jupyter notebook list will give nothing it can be done in two steps
1)

kill $(pgrep jupyter)

if when start a new instance you are getting

Jupyter command "jupyter-lab" not found.

just reactivate enviroment on which you are starting jupyter lab e.g.
2)

conda activate base
MosQuan
  • 85
  • 1
  • 11