Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

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.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!