[issue1565525] tracebacks eat up memory by holding references to locals and globals when they are not wanted
Greg Hazel
report at bugs.python.org
Sat Jun 26 02:45:46 CEST 2010
Greg Hazel <ghazel at users.sourceforge.net> added the comment:
The objects I do want in the traceback are the objects necessary to print a traceback, but not the locals and globals of each frame.
For example:
def bar():
x = "stuff"
raise Exception("example!")
bar()
prints:
Traceback (most recent call last):
Line 4, in <module>
bar()
Line 3, in bar
raise Exception("example!")
Exception: example!
There is no reason in that example to have a reference to "x" in the traceback, since it's not used in the output. This becomes important when I try to save a reference to the traceback object and raise it later:
import sys
def bar():
x = "stuff"
raise Exception("example!")
try:
bar()
except:
exc_info = sys.exc_info()
def foo(e):
raise e[0], e[1], e[2]
# sometime possibly much later...
foo(exc_info)
Traceback (most recent call last):
Line 12, in <module>
foo(exc_info)
Line 6, in <module>
bar()
Line 4, in bar
raise Exception("example!")
Exception: example!
During that "sometime possibly much later..." comment, a reference to "x" is held, when it will not be used in printing the traceback later. So, I would not like to keep a reference to "x", and currently there is no way to do that without also dropping a reference to the data needed to print the traceback.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1565525>
_______________________________________
More information about the Python-bugs-list
mailing list