On 18 September 2017 at 20:18, Victor Stinner <victor.stin...@gmail.com> wrote: > 2017-09-18 12:07 GMT+02:00 Nick Coghlan <ncogh...@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: 1. If the exception ref count == 1, just drop the reference and let the traceback die with it 2. If the exception ref count > 1, check for a new "__keep_locals__" attribute 3. If it's true, just drop the reference and otherwise leave the exception alone 4. 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 | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com