sizo_abe
sizo_abe

Reputation: 501

Stop Execution of Databricks notebook after specific cell

Please suggest how to stop the execution of code after a specific cell in a Databricks notebook.

I Tried sys.exit(0) (Python code) and dbutils.notebook.exit() on Databricks notebook. However, neither worked.

Upvotes: 23

Views: 50401

Answers (2)

Robert
Robert

Reputation: 431

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")

Upvotes: 43

sizo_abe
sizo_abe

Reputation: 501

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')

Upvotes: 7

Related Questions