Add hasattr checks to prevent faulty __del__.
This commit is contained in:
parent
5b310e6d7c
commit
b89da5dec2
1 changed files with 9 additions and 3 deletions
|
@ -706,7 +706,13 @@ class PDBSQLMixin:
|
||||||
self.savepoints = []
|
self.savepoints = []
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
# Wrapped in hasattr because if the object fails __init__, Python will
|
||||||
|
# still call __del__ and thus close(), even though the attributes
|
||||||
|
# we're trying to clean up never got set.
|
||||||
|
if hasattr(self, 'sql'):
|
||||||
self.sql.close()
|
self.sql.close()
|
||||||
|
|
||||||
|
if hasattr(self, 'ephemeral'):
|
||||||
if self.ephemeral:
|
if self.ephemeral:
|
||||||
self.ephemeral_directory.cleanup()
|
self.ephemeral_directory.cleanup()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue