Skip to content
Myr

looking for a jinja memleak

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 116b91c · Browse files · 3 files+36 added−40 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+36 added−40 removed

  • other:+36 added−40 removed

3 files+36 added−40 removed

modified:jinja/translators/python.py+1 added-2 removed
267 unmodified lines
268 """269 if self.closed:270 raise RuntimeError('translator is closed')271 if node.__class__ in self.handlers:272 out = self.handlers[node.__class__](node)272 return self.handlers[node.__class__](node)273 else:274 raise AssertionError('unhandled node %r' % node.__class__)275 return out275276 def close(self):277 """278 Clean up stuff.
888 unmodified lines
modified:jinja/parser.py+30 added-22 removed
1115 unmodified lines
1116 self.stream.lineno, self.filename)11171118 return assemble_list()11191120 def sanitize_tree(self, body, extends):1121 self._sanitize_tree([body], [body], extends, body)1122 return body11231124 def _sanitize_tree(self, nodelist, stack, extends, body):1125 """1126 This is not a closure because python leaks memory if it is. It's used1127 by `parse()` to make sure blocks do not trigger unexpected behavior.1128 """1129 for node in nodelist:1130 if extends is not None and \1131 node.__class__ is nodes.Block and \1132 stack[-1] is not body:1133 for n in stack:1134 if n.__class__ is nodes.Block:1135 break1136 else:1137 raise TemplateSyntaxError('misplaced block %r, '1138 'blocks in child '1139 'templates must be '1140 'either top level or '1141 'located in a block '1142 'tag.' % node.name,1143 node.lineno,1144 self.filename)1145 stack.append(node)1146 self._sanitize_tree(node.get_child_nodes(), stack, extends, body)1147 stack.pop()11481149 def parse(self):1150 """1151 Parse the template and return a Template node. This also does some1152 post processing sanitizing and parses for an extends tag.
17 unmodified lines
1170 extends = None1171 if leading_whitespace:1172 self.stream.shift(leading_whitespace)11731145 body = self.subparse(None)1146 def walk(nodelist, stack):1147 for node in nodelist:1148 if extends is not None and \1149 node.__class__ is nodes.Block and \1150 stack[-1] is not body:1151 for n in stack:1152 if n.__class__ is nodes.Block:1153 break1154 else:1155 raise TemplateSyntaxError('misplaced block %r, '1156 'blocks in child '1157 'templates must be '1158 'either top level or '1159 'located in a block '1160 'tag.' % node.name,1161 node.lineno,1162 self.filename)1163 stack.append(node)1164 walk(node.get_child_nodes(), stack)1165 stack.pop()1166 walk([body], [body])1174 body = self.sanitize_tree(self.subparse(None), extends)1175 return nodes.Template(extends, body, 1, self.filename)1176 finally:1177 self.close()1178
5 unmodified lines
modified:jdebug.py+5 added-16 removed
17 unmodified lines
181920__all__ = ['e', 't', 'p', 'l', 'm']212223_global_frame = sys._getframe()24e = Environment()25t = e.from_string262726if os.environ.get('JDEBUG_SOURCEPRINT'):27 original_translate = PythonTranslator.translate2829 def debug_translate(self):30 rv = original_translate(self)31 sys.stderr.write('## GENERATED SOURCE:\n%s\n' % rv)32 return rv3334 PythonTranslator.translate = debug_translate353628def p(x=None, f=None):29 if x is None and f is not None:30 x = e.loader.get_source(f)31 print PythonTranslator(e, Parser(e, x, f).parse(), None).translate()
11 unmodified lines
43 self.clear = self.guarded_objects.clear4445 def freeze(self):46 self.clear()56 self.update()5758 def update(self):59 self.guarded_objects.clear()47 for obj in gc.get_objects():48 self.guarded_objects[id(obj)] = True4950 def get_delta(self):51 frm = sys._getframe()52 result = []53 for obj in gc.get_objects():66 if id(obj) not in self.guarded_objects:54 if id(obj) not in self.guarded_objects and \55 obj is not frm and obj is not result:56 result.append(obj)57 return result5859
11 unmodified lines