Add hasattr checks to prevent faulty __del__.

This commit is contained in:
voussoir 2018-03-13 02:20:17 -07:00
parent 5b310e6d7c
commit b89da5dec2

View file

@ -706,9 +706,15 @@ class PDBSQLMixin:
self.savepoints = [] self.savepoints = []
def close(self): def close(self):
self.sql.close() # Wrapped in hasattr because if the object fails __init__, Python will
if self.ephemeral: # still call __del__ and thus close(), even though the attributes
self.ephemeral_directory.cleanup() # we're trying to clean up never got set.
if hasattr(self, 'sql'):
self.sql.close()
if hasattr(self, 'ephemeral'):
if self.ephemeral:
self.ephemeral_directory.cleanup()
def commit(self): def commit(self):
while len(self.on_commit_queue) > 0: while len(self.on_commit_queue) > 0: