closes #62295: avoid "OSError: Too many open files"

by moving .file_stream as a Module property opening the file only when needed

authorSylvain Thénault <sylvain.thenault@logilab.fr>
changesetdf946b92d8fe
branchdefault
phasepublic
hiddenno
parent revision#cd5d87c447fe Make sure that the name attribute on lambda nodes is defined,
child revision#2bb5506e9c14 0.23.1
files modified by this revision
ChangeLog
builder.py
scoped_nodes.py
# HG changeset patch
# User Sylvain Thénault <sylvain.thenault@logilab.fr>
# Date 1323351093 -3600
# Thu Dec 08 14:31:33 2011 +0100
# Node ID df946b92d8fee5510179696fc67910b4a57ca356
# Parent cd5d87c447fef1172365e186a9e204014d0a1fa8
closes #62295: avoid "OSError: Too many open files"

by moving .file_stream as a Module property opening the file only when needed

diff --git a/ChangeLog b/ChangeLog
@@ -1,8 +1,12 @@
1  Change log for the astng package
2  ================================
3 
4 +--
5 +    * #62295: avoid "OSError: Too many open files" by moving
6 +      .file_stream as a Module property opening the file only when needed
7 +
8  2011-10-07  --  0.23.0
9      * #77187: ancestor() only returns the first class when inheriting
10        from two classes coming from the same module
11 
12      * #76159: putting module's parent directory on the path causes problems
diff --git a/builder.py b/builder.py
@@ -126,11 +126,10 @@
13              except ImportError:
14                  modname = splitext(basename(path))[0]
15          # build astng representation
16          node = self.string_build(data, modname, path)
17          node.file_encoding = encoding
18 -        node.file_stream = stream
19          return node
20 
21      def string_build(self, data, modname='', path=None):
22          """build astng from source code string and return rebuilded astng"""
23          module = self._data_build(data, modname, path)
diff --git a/scoped_nodes.py b/scoped_nodes.py
@@ -241,10 +241,16 @@
24          self.doc = doc
25          self.pure_python = pure_python
26          self.locals = self.globals = {}
27          self.body = []
28 
29 +    @property
30 +    def file_stream(self):
31 +        if self.file is not None:
32 +            return file(self.file)
33 +        return None
34 +
35      def block_range(self, lineno):
36          """return block line numbers.
37 
38          start from the beginning whatever the given lineno
39          """