diff options
author | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2014-11-22 14:15:28 +0200 |
---|---|---|
committer | Claudiu Popa <cpopa@cloudbasesolutions.com> | 2014-11-22 14:15:28 +0200 |
commit | 798948837f5a49ea6f4ee1302c7417ee24790882 (patch) | |
tree | b7f94a175f2746b93f2468cf0c44923e994fe472 | |
parent | a739fbd50862f41d13991587ce8638a1d2baeffd (diff) | |
download | pylint-798948837f5a49ea6f4ee1302c7417ee24790882.tar.gz |
Close the file_stream of the ast node after analysing it.
This ensures that we don't leak open fds and that we are well-behavioured
for PyPy (previously, the file were closed due to gc).
-rw-r--r-- | lint.py | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -846,6 +846,20 @@ class PyLinter(OptionsManagerMixIn, MessagesHandlerMixIn, ReportsHandlerMixIn, def check_astroid_module(self, astroid, walker, rawcheckers, tokencheckers): """check a module from its astroid representation, real work""" + try: + return self._check_astroid_module(astroid, walker, + rawcheckers, tokencheckers) + finally: + # Close file_stream, if opened, to avoid to open many files. + if astroid.file_stream: + astroid.file_stream.close() + # TODO(cpopa): This is an implementation detail, but it will + # be moved in astroid at some point. + # We invalidate the cached property, to let the others + # modules which relies on this one to get a new file stream. + del astroid.file_stream + + def _check_astroid_module(self, astroid, walker, rawcheckers, tokencheckers): # call raw checkers if possible try: tokens = tokenize_module(astroid) |