โ11-18-2019 12:59 PM
I am using Python notebooks as part of a concurrently running workflow with Databricks Runtime 6.1.
Within the notebooks I am using try/except blocks to return an error message to the main concurrent notebook if a section of code fails. However I have noticed that in the last block of execution the "except" exit text will be returned regardless of an error in the "try" block.
Running this code highlights the problem:
try:
a = 5
dbutils.notebook.exit("a equals 5")
except:
dbutils.notebook.exit("Still printing exception")
โ11-18-2019 11:25 PM
โ11-18-2019 11:25 PM
โ11-19-2019 05:21 AM
That's odd, it's working for me now also. I tried this in different notebooks attached to the same cluster, I wonder if it was some odd cluster behavior. Thanks for checking.
โ06-24-2020 11:09 PM
dbutils.notebook.exit() will raise an exception
In the answer provided by @Shyamprasad Miryalaโ above the print inside of except does not get printed because notebook.exit() text takes priority over any other print().
Look at this example:
%python a = 0 try: a = 1 dbutils.notebook.exit("Inside try") except Exception as ex: a = 2 dbutils.notebook.exit("Inside exception")
Output: Notebook exited: Inside exception
%python print(a)
Output: 2
โ10-07-2020 04:20 AM
SO if i want to exit with try block dbutils.notebook.exit("Inside try").What is the process?
โ08-04-2021 02:07 AM
You can add a fake except for the notebook.exit inside try block
try:notebook.run(somenotebook)
try:
notebook.exit()
except Exception as e
print("Notebook exited")
except:
print("Main exception")
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