Stop cell execution in notebook
Sometimes you would like to stop execution of cells.
There is a
Stop that can be used to stop execution of cells in Jupyter Notebook from Python code.
In this example, you will learn how to use
Stop function. We will use
Checkbox widget to call
Cells below called
Stop() function will not be executed.
You will need
mercury package to run this example.
In the first cell, please import required packages:
import mercury as mr
should_stop = mr.Checkbox(value=False, label="Should we stop?")
Checkbox is switched on:
if should_stop.value: print("We stop execution here!") mr.Stop()
Let's add some code just to see the
print("Some code ...")
The notebook's code in the Jupyter Notebook:
Please start Mercury in the same directory as notebook:
You will see the app running at
http://127.0.0.1:8000. Below is an animation with Mercury App:
Mercury automatically executes cells after
Checkbox update. The
Stop() functions stops cells execution.
Notebook from this example is available in the mercury-examples (opens in a new tab) repository.