summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudiu Popa <cpopa@cloudbasesolutions.com>2014-11-22 14:15:28 +0200
committerClaudiu Popa <cpopa@cloudbasesolutions.com>2014-11-22 14:15:28 +0200
commit798948837f5a49ea6f4ee1302c7417ee24790882 (patch)
treeb7f94a175f2746b93f2468cf0c44923e994fe472
parenta739fbd50862f41d13991587ce8638a1d2baeffd (diff)
downloadpylint-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.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/lint.py b/lint.py
index 1b46b90..df25e43 100644
--- a/lint.py
+++ b/lint.py
@@ -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)