[Python-ideas] feature to make traceback objects usable without references to frame locals and globals

Antoine Pitrou solipsis at pitrou.net
Sat Jun 26 14:00:31 CEST 2010


On Sat, 26 Jun 2010 13:03:38 +0200
"M.-A. Lemburg" <mal at egenix.com> wrote:
> Greg Ewing wrote:
> > ghazel at gmail.com wrote:
> > 
> >> I'm interested in a feature which allows users to discard the locals
> >> and globals references from frames held by a traceback object.
> 
> Wouldn't it be better to write safer code and not store
> a reference to the traceback object in the first place ?

In Python 3, tracebacks are stored as an attribute of the corresponding
exception:

>>> try: 1/0
... except Exception as _: e = _
... 
>>> e.__traceback__
<traceback object at 0x7ff69fdbf908>

> Also: What's the use case for creating traceback objects
> outside the Python interpreter core ?

He's not talking about creating traceback objects outside the core, but
being able to reuse tracebacks created by the core without keeping alive
a whole chain of objects.

It's a real need when you want to do careful error handling/reporting
without wasting too many resources. As already mentioned, Twisted has a
bunch of code to work around that problem, since errors can be quite
long-lived in a pipelined asynchronous execution model.


Antoine.





More information about the Python-ideas mailing list