[Python-Dev] Reference cycles in Exception.traceback (original) (raw)
Victor Stinner victor.stinner at gmail.com
Fri Mar 7 00:38:27 CET 2014
- Previous message: [Python-Dev] Reference cycles in Exception.__traceback__
- Next message: [Python-Dev] Reference cycles in Exception.__traceback__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
2014-03-06 16:19 GMT+01:00 Victor Stinner <victor.stinner at gmail.com>:
By the way, here is my test script to try to create a lightweight traceback object without references to locals: https://bitbucket.org/haypo/misc/src/tip/python/suppresslocals.py
It works if there is no chained exception.
I updated my proof-of-concept to support Exception.context, Exception.cause and Exception.suppress_context: https://bitbucket.org/haypo/misc/src/tip/python/suppress_locals.py
It creates a lightweight "view" of an exception only keeping information needed to format a traceback.
The problem is to build something working with the traceback module. I should maybe write my own formatting function reusing some traceback functions.
I reused as much code as possible of the traceback module. I only reimplemented _iter_chain() and _format_exception_iter().
View classes could be simplified, but it would need to modify more code in the traceback module.
What do you think of my approach? Would it be something useful in other applications? If yes, I can maybe work on a a better implementation, and maybe on a PEP, to see how such thing could be integrated in Python stdlib. It can maybe directly be part of the traceback module.
I don't know if storing an exception to maybe format it later as a traceback is a common use case. Usually, exceptions are immediatly formatted or dropped, no?
Victor
- Previous message: [Python-Dev] Reference cycles in Exception.__traceback__
- Next message: [Python-Dev] Reference cycles in Exception.__traceback__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]