pythonjupyter-notebookjupyter

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


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


Solution

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