Skip to content

Commit ae3eb0f

Browse files
CJStuartsusodapop
authored andcommitted
Handle close exceptions quietly on __del__
## What changes are proposed in this pull request? Handle exceptions and log as debug level when __del__ fails to close the connection. #168466 is resolved by databricks/master.
1 parent 959060d commit ae3eb0f

File tree

1 file changed

+6
-1
lines changed
  • cmdexec/clients/python/src/databricks/sql

1 file changed

+6
-1
lines changed

cmdexec/clients/python/src/databricks/sql/client.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from databricks.sql import USER_AGENT_NAME, __version__
1212
from databricks.sql import *
13+
from databricks.sql.exc import OperationalError
1314
from databricks.sql.thrift_backend import ThriftBackend
1415
from databricks.sql.utils import ExecuteResponse, ParamEscaper
1516
from databricks.sql.types import Row
@@ -123,7 +124,11 @@ def __del__(self):
123124
if self.open:
124125
logger.debug("Closing unclosed connection for session "
125126
"{}".format(self.get_session_id()))
126-
self._close(close_cursors=False)
127+
try:
128+
self._close(close_cursors=False)
129+
except OperationalError as e:
130+
# Close on best-effort basis.
131+
logger.debug("Couldn't close unclosed connection: {}".format(e.message))
127132

128133
def get_session_id(self):
129134
return self.thrift_backend.handle_to_id(self._session_handle)

0 commit comments

Comments
 (0)