Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop execution of all cells in Jupyter Notebook

Suppose I executed all cells in a Jupyter Notebook, and want to interrupt the computation in the middle. How can I stop the execution of all cells?

"Kernel interrupt" only interrupts the execution of the current cell, but then immediately continues with all remaining cells. Instead, I do not want to execute all remaining cells after hitting "Kernel interrupt". How can I do that?

I am running version 4.2.3 with Python 3.5.2, packaged by conda-forge

like image 494
MarcelSimon Avatar asked Nov 11 '16 18:11

MarcelSimon


People also ask

How do you stop running all cells in Jupyter notebook?

To stop running a piece of code, press the stop button. To create new cells, use the plus (+) button in the toolbar or hit SHIFT+ENTER on the last cell in the Notebook.

How do you stop an infinite loop in Jupyter?

Ctrl+C should break out of an infinite loop while a cell is running.


1 Answers

If you know it beforehand, where you want to stop (e.g have code below that takes long and doesn't need to be executed every run), you can add a

    raise SystemExit("Stop right there!")

whereever you want to stop.

Everything below isn't executed, since an exception has been thrown and when using the SystemExit Exception no stacktrace is shown by default.
The kernel doesn't exit, so you can still execute everything by hand afterwards.

like image 66
dCSeven Avatar answered Dec 16 '22 05:12

dCSeven