[Python-Dev] Evil reference cycles caused Exception.traceback (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Mon Sep 18 06:35:02 EDT 2017
- Previous message (by thread): [Python-Dev] Evil reference cycles caused Exception.__traceback__
- Next message (by thread): [Python-Dev] Evil reference cycles caused Exception.__traceback__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 18 September 2017 at 20:18, Victor Stinner <victor.stinner at gmail.com> wrote:
2017-09-18 12:07 GMT+02:00 Nick Coghlan <ncoghlan at gmail.com>:
I wonder if it might be reasonable to have tracebacks only hold a weak reference to their frame objects when "debug == False". Please don't change the Python behaviour depending on debug, or it will be a nightmare to debug it :-( ("Why does it work on my computer?")
Yeah, that's always a challenge :)
Rather than being thread local or context local state, whether or not to keep the full frames in the traceback could be a yet another setting on the exception object, whereby we tweaked the logic that drops the reference at the end of an except clause as follows:
- If the exception ref count == 1, just drop the reference and let the traceback die with it
- If the exception ref count > 1, check for a new "keep_locals" attribute
- If it's true, just drop the reference and otherwise leave the exception alone
- If it's false, recursively clear all the already terminated frames in traceback, context, and cause
For now, we'd default to "keep_locals = True", but we'd attempt to figure out some way to migrate to the default being "keep_locals = False".
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message (by thread): [Python-Dev] Evil reference cycles caused Exception.__traceback__
- Next message (by thread): [Python-Dev] Evil reference cycles caused Exception.__traceback__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]