Skip to content

Commit 898e601

Browse files
committed
Close cache file properly
Fixes (reported by python 3.6): Exception ignored in: <_io.FileIO name='/Users/michkapopoff/repo/pygccxml/unittests/data/new_cache.cache' mode='rb' closefd=True> ResourceWarning: unclosed file <_io.BufferedReader name='/Users/michkapopoff/repo/pygccxml/unittests/data/new_cache.cache'>
1 parent 483f597 commit 898e601

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pygccxml/parser/declarations_cache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,16 @@ def __load(file_name):
220220
% (file_name, len(list(cache.keys()))))
221221
except Exception as error:
222222
file_cache_t.logger.exception(
223-
"Error occured while reading cache file: %s",
223+
"Error occurred while reading cache file: %s",
224224
error)
225225
cache_file_obj.close()
226226
file_cache_t.logger.info(
227227
"Invalid cache file: [%s] Regenerating." %
228228
file_name)
229229
open(file_name, 'w+b').close() # Create empty file
230230
cache = {} # Empty cache
231+
finally:
232+
cache_file_obj.close()
231233
return cache
232234

233235
def flush(self):

0 commit comments

Comments
 (0)