cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How can I exit from a Notebook which is used as a job?

User16301465121
New Contributor

How can I quit from a notebook in the middle of an execution based on some condition?

3 REPLIES 3

arsalan1
Contributor

@Mohan Kolli

The simple way to terminate execution based on a condition is to throw an exception; doing so will cause the run to terminate immediately. However, doing so will also cause the job to have a 'Failed' status.

In order to to maintain correctness semantics, you'd need to wrap each command in in a Try/Catch clause, and if the particular condition is met to simply perform a No-Op so that the run will complete successfully.

Josh
New Contributor II

This does not work. When I have a cell (I am using pyspark) that has the command:

quit()

Databricks skips over that particular cell,but still runs the next cell.

SamsonXia
New Contributor II

exit(value: String): void

Calling

dbutils.notebook.exit

in a job causes the notebook to complete successfully. If you want to cause the job to fail, throw an exception.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group