Przeglądaj źródła

Add destructor which closes the mongo connection

ogert 5 lat temu
rodzic
commit
596231848f

+ 7 - 3
cdplib/db_handlers/MongodbHandler.py

@@ -84,6 +84,13 @@ class MongodbHandler:
 
         self._database_name = database_name
 
+    def __del__(self):
+        try:
+            self._client.close()
+        except Exception as e:
+            self._log.log_and_raise_error(('An error occured when trying to dispose the SQL engine. Error: {}').format(e))
+    
+
     def set_database(self, database_name: str):
         '''
         :param str database_name: Name of the database.
@@ -95,9 +102,6 @@ class MongodbHandler:
             self._log.info(('Database: {} didnt exist, it will be created for you once a collection is created in it').format(database_name))
         self._database = self._client[database_name]
 
-    def __del__(self):
-        self._client.close()
-
     def drop_database(self):
         '''
         '''

+ 1 - 1
cdplib/db_handlers/SQLHandler.py

@@ -638,5 +638,5 @@ class SQLHandler:
     def dispose_engine(self):
         try:
             self._engine.dispose()
-        except Exception e:
+        except Exception as e:
             self._log.log_and_raise_error(('An error occured when trying to dispose the SQL engine. Error: {}').format(e))