Stop execution of Colab notebook from within a cell based on condition

Viewed 498

Basically what I am trying to do is if a condition is met, then the execution of the current cell and all subsequent cells is canceled. Here is the idea if exit() stopped the notebook execution (but it only stops the execution of the cell it is run in)

yes_and_no_list = ['yes', 'y', 'no', 'n']
response = ''
while not response.lower() in yes_and_no_list:
  response = input("Continue running notebook?")

if response in yes_and_no_list[2:]:
    print("Notebook execution aborted.")
    exit()

....so I am wondering if there is piece of code or a notebook magic that I can replace 'exit()' with and will stop the execution of the entire Colab notebook?

I have tried the response to this question: How to terminate current colab session from notebook cell

...but if I replace exit() with !kill $(ps aux | awk '{print $2}') it doesn't seem to print the line above it, "Notebook execution aborted.", so I am confused by how it works.

0 Answers
Related