Skip to content

Commit

Permalink
Handle __del__ more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoretti committed Nov 3, 2023
1 parent dc3a230 commit d08b220
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion exasol/driver/websocket/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,16 @@ def cursor(self):
return DefaultCursor(self)

def __del__(self):
self.close()
if self._connection is None:
return

# Currently, the only way to handle this gracefully is to invoke the`__del__`
# method of the underlying connection rather than calling an explicit `close`.
#
# For more details, see also:
# * https://github.com/exasol/sqlalchemy-exasol/issues/390
# * https://github.com/exasol/pyexasol/issues/108
#
# If the above tickets are resolved, it should be safe to switch back to using
# `close` instead of `__del__`.
self._connection.__del__()
2 changes: 1 addition & 1 deletion test/integration/regression/test_regression_bug390.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def test_connection_with_block_cleans_up_properly(pytester, itde):
pytester.makepyfile(
# fmt: off
cleandoc(
f"""
f"""
from sqlalchemy import create_engine
def test():
Expand Down

0 comments on commit d08b220

Please sign in to comment.