How to shutdown jupyter notebook app (server) without using ctrl-c?

Question:

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)?

Asked By: patapouf_ai

||

Answers:

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

Answered By: Anton Hulikau

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.

Answered By: patapouf_ai

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

Answered By: Ryan Charmley

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

Answered By: Harry

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.

Answered By: Joe Fagan

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
Answered By: MosQuan
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.