Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPython notebook - configuring to shut down the kernel on closing the tab

On the official site it is said:

When a notebook is opened, its “computational engine” (called the kernel) is automatically started. Closing the notebook browser tab, will not shut down the kernel, instead the kernel will keep running until is explicitly shut down."

Is it possible to configure the iPython server so that the kernel is killed together with the associated tab?

like image 875
Nikolay Gromov Avatar asked Sep 28 '15 13:09

Nikolay Gromov


People also ask

How do I shutdown a jupyter notebook kernel?

To shut down a kernel, go to the associated notebook and click on menu File -> Close and Halt. Alternatively, the Notebook Dashboard has a tab named Running that shows all the running notebooks (i.e. kernels) and allows shutting them down (by clicking on a Shutdown button).

How do you keep a jupyter notebook running after closing the browser tab?

This can be done by typing jupyter notebook in the terminal, which will open a browser. Then, navigate to the respective jupyter notebook file in the browser and open it. Click Cell > Run All on the toolbar. All done!

How do you stop a cell from running in a jupyter notebook?

Stopping a process or restarting a Jupyter Notebook To interrupt a cell execution, you can click the ■ “stop” button in the ribbon above the notebook, or select “Interrupt Kernel” from the Kernel menue.


1 Answers

After some research and numerous tries the solution is extremely simple. Add at the end of the file profile/static/custom/custom.js the following code:

$( window ).unload(function() {
  IPython.notebook.kernel.kill();
});

Works for me perfectly! (tried on Chrome)

like image 94
Nikolay Gromov Avatar answered Nov 09 '22 07:11

Nikolay Gromov