Browse code

utils/kamctl: dbtextdb.py close previous opened file properly

related #1747

Victor Seva authored on 04/05/2020 13:22:36
Showing 1 changed files
... ...
@@ -60,6 +60,10 @@ class DBText(object):
60 60
         if not os.path.isdir(location):
61 61
             raise ParseError(location + ' is not a directory')
62 62
 
63
+    def __del__(self):
64
+        if getattr(self, 'fd', False):
65
+            self.fd.close()
66
+
63 67
     def _ParseOrderBy(self):
64 68
         """Parse out the column name to be used for ordering the dataset.
65 69
 
... ...
@@ -438,6 +442,8 @@ class DBText(object):
438 442
         self.command = ''     # which command are we executing
439 443
         self.strings = []     # list of string literals parsed from the query
440 444
         self.parens = []      # list of parentheses parsed from the query
445
+        if getattr(self, 'fd', False):
446
+            self.fd.close()
441 447
 
442 448
     def ParseQuery(self, query):
443 449
         """External wrapper for the query parsing routines.