Stop Execution of Databricks notebook after specific cell

Viewed 11733

I Tried sys.exit(0)(Python code) and dbutils.notebook.exit() on Databricks notebook. But both the option didn't work. Please suggest any other way to stop the execution of code after a specific cell in Databricks notebook.

2 Answers

dbutils.notebook.exit() does not work because you need to put the string argument, it fails silently without it. To make it work you should write something like:

dbutils.notebook.exit("whatever reason to make it stop")

Just use this. And click on run all cell button on Databricks notebook. If the condition is satisfied then execution will be stopped. Worked for me.

if (df.shape[0]==0): dbutils.notebook.exit('stop')

Related