How to Gracefully Close Jupyter Notebook


If you are running Jupyter Notebook on your local Mac/Windows device and you want to make sure that you did close the application gracefully, then here are a few ways to do it.

Option 1: Using the Menu Option

    This is the the best and the ideal way to close a Notebook application.

    Simply go to Menu: File and select Shut Down at the bottom.

    Shut Down Jupyter Notebook via File Menu

    You will get an alert asking if you really want o shutdown JupyterLab.

    Shutdown confirmation - Please confirm you want to shut down JupyterLab

    Once you click on "Shut Down" button, you will notice that the Command Line/Terminal that was running the Notebook server gets closed and so does the Browser tab.


Option 2: Using Command "jupyter notebook stop"

    Open a new instance of your Terminal (CMD if on Windows) and run the below command.

    jupyter notebook stop

    You will notice that the Jupyter Notebook Server has stopped with logs as,

    [I 2023-07-26 03:53:25.476 ServerApp] Shutting down on /api/shutdown request.
    [I 2023-07-26 03:53:25.476 ServerApp] Shutting down 6 extensions

Option 3: The Quickest way - Control + C Twice

    This is the quickest way to terminate a Notebook server, by pressing Control + C twice on the console.

    ^C[I 2023-07-26 03:55:33.181 ServerApp] interrupted
    [I 2023-07-26 03:55:33.182 ServerApp] Serving notebooks from local directory: /Users/c2ctechtv
        0 active kernels
        Jupyter Server 2.7.0 is running at:
        http://localhost:8888/tree?token=9dc1b9a830102024b31a2e78069f69469185eb19b9eb2223
            http://127.0.0.1:8888/tree?token=9dc1b9a830102024b31a2e78069f69469185eb19b9eb2223
    Shutdown this Jupyter server (y/[n])? y
    [C 2023-07-26 03:55:34.759 ServerApp] Shutdown confirmed
    [I 2023-07-26 03:55:34.761 ServerApp] Shutting down 6 extensions

    When you press Control + C once you will see a message on console "Shutdown this Jupyter server (y/[n])" if you press Control + C again or type y will shutdown the server.

    Shutting Down Jupyter Notebook Server using Control + C

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap