Is there a way to catch the cancel button or the interrupt button in a Databricks notebook?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 12:40 PM
I'm running oracledb package and it uses sessions. When you cancel a running query it doesn't close the session even if you have a try catch block because a cancel or interrupt issues a kill command on the process. Is there a method to catch the cancel or interrupt? In an ipynb notebook I could use except KeyboardInterrupt.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2023 09:29 PM
Please share a code block by that we can test in our system and provide you correct solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-12-2023 07:18 PM
Just find yourself a long running query or create a view that cross joins a quadrillion records (make sure you have the ability to kill this session). Then import oracledb in a notebook, connect to that server, and query that long running query. Proceed to hit cancel in the notebook cell or interrupt in the notebook at the top right. The session doesn't close, you'd need to connection.close(force=True) or pool.close(force=True).
What i'm looking for is a way to catch the 'cancel' button in a cell or the 'interrupt' button in a notebook so I can capture this in a try: except: block and issue the close() command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2023 11:54 PM
Hi @Jordan Fox
Hope everything is going great.
Just wanted to check in if you were able to resolve your issue. If yes, would you be happy to mark an answer as best so that other members can find the solution more quickly? If not, please tell us so we can help you.
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 09:40 AM
I'm having the same issue and this has been frustrating as heck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
I was having the same issue and I think I was finally able to solve it!
When you simply except and capture the KeyboardInterrupt signal and do not raise it, the notebook gets into an endless cycle of "interrupting..." and never does anything.
However, if you catch the KeyboardInterrupt exception, do what you want to do, and then raise it, the notebook finishes as expected.
Funny thing is that I couldn't get the exception handling block to print anything to the cell's output...
But I know it was executed because I wrote a file during the exception handling, and it was there after.
Solution below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
oh my gosh brilliant thank you!!
![](/skins/images/8C2A30E5B696B676846234E4B14F2C7B/responsive_peak/images/icon_anonymous_message.png)
![](/skins/images/8C2A30E5B696B676846234E4B14F2C7B/responsive_peak/images/icon_anonymous_message.png)