How to close IPython Notebook properly?

Posted on

Question :

How to close IPython Notebook properly?

How to close IPython Notebook properly?

Currently, I just close the browser tabs and then use Ctrl+C in the terminal.
Unfortunately, neither exit() nor ticking Kill kernel upon exit does help (they do kill the kernel they but don’t exit the iPython).

Answer #1:

There isn’t currently a better way to do it than Ctrl+C in the terminal.

We’re thinking about how to have an explicit shutdown, but there’s some tension between the notebook as a single-user application, where the user is free to stop it, and as a multi-user server, where only an admin should be able to stop it. We haven’t quite worked out how to handle the differences yet.

(For future readers, this is the situation with 0.12 released and 0.13 in development.)

Update December 2017

The IPython Notebook has become the Jupyter Notebook. A recent version has added a jupyter notebook stop shell command which will shut down a server running on that system. You can pass the port number at the command line if it’s not the default port 8888.

You can also use nbmanager, a desktop application which can show running servers and shut them down.

Finally, we are working on adding:

  • A config option to automatically shut down the server if you don’t use it for a specified time.
  • A button in the user interface to shut the server down. (We know it’s a bit crazy that it has taken this long. Changing UI is controversial.)
Answered By: Thomas K

Answer #2:

If you run jupyter in the background like me:

jupyter notebook &> /dev/null &

Then to exit jupyter completely, instead of Ctl-C, make an alias command:

echo 'alias quitjupyter="kill $(pgrep jupyter)"' >> ~/.bashrc

Restart your terminal. Kill all jupyter instances:


Note: use double quotes inside of single quotes as shown above. The other way around will evaluate the expression before writing it to your .bashrc (you want to write the command itself not ‘kill 1430’ or whatever process number may be associated with a current jupyter instance). Of course you can use any alias you wish. I actually use ‘qjup’:

echo 'alias qjup="kill $(pgrep jupyter)"' >> ~/.bashrc

Restart your terminal. Kill all jupyter instances:

Answered By: BBW Before Windows

Answer #3:

I think accepted answer outdated and is not valid anymore.

You can terminate jupyter notebook from web interface on file menĂ¼ item.

enter image description here

When you move Mouse cursor on “close and halt”, you will see following explanation.

enter image description here

And when you click “close and halt”, you will see following message on terminal screen.

enter image description here

Answered By: wasabi

Answer #4:

First step is to save all open notebooks. And then think about shutting down your running Jupyter Notebook. You can use this simple command:

$ jupyter notebook stop 
Shutting down server on port 8888 ...

Which also takes the port number as argument and you can shut down the jupyter notebook gracefully.

For eg:

jupyter notebook stop 8889 
Shutting down server on port 8889 ...

Additionally to know your current jupyter instance running, check below command:

shell> jupyter notebook list 
Currently running servers:
http://localhost:8888/?token=ef12021898c435f865ec706de98632 :: /Users/username/jupyter-notebooks [/code]
Answered By: moronkreacionz

Answer #5:

These commands worked for me:

jupyter notebook list # shows the running notebooks and their port-numbers
                      # (for instance: 8080)
lsof -n -i4TCP:[port-number] # shows PID.
kill -9 [PID] # kill the process.

This answer was adapted from here.

Answered By: PatriceG

Answer #6:

Try killing the pythonw process from the Task Manager (if Windows) if nothing else works.

Answered By: fixxxer

Answer #7:

Linux (Ubuntu 14.04)

As mentioned, try to kill ipython notebook processes properly by first going to the “running” tab in your ipynb/jupyter browser session, and then check open terminals on your console and shut down with ctrl-c. The latter should be avoided if possible.

If you run an ipython notebook list and continue to see running ipython servers at different ports, make note of which ports the existing notebooks are being served to. Then shut down your TCP ports:

fuser -k 'port#'/tcp 

I’m not sure if there are other risks involved with doing this. If so, let me know.

Answered By: Soham

Answer #8:

Actually, I believe there’s a cleaner way than killing the process(es) using kill or task manager.

In the Jupyter Notebook Dashboard (the browser interface you see when you first launch ‘jupyter notebook’), browse to the location of notebook files you have closed in the browser, but whose kernels may still be running.

iPython Notebook files appear with a book icon, shown in green if it has a running kernel, or gray if the kernel is not running.

Just select the tick box next to the running file, then click on the Shutdown button that appears above it.

This will properly shut down the kernel associated with that specific notebook.

Answered By: Andrew Medlin

Leave a Reply

Your email address will not be published.