diff options
author | Andrew Kuchling <amk@amk.ca> | 2013-09-15 18:15:56 -0400 |
---|---|---|
committer | Andrew Kuchling <amk@amk.ca> | 2013-09-15 18:15:56 -0400 |
commit | 173a157e725579eec1f28f8c9d53d6761ba6c79f (patch) | |
tree | 98be7afea0a4f929f07193d94ffe86cc0e7739e0 /Lib/traceback.py | |
parent | Issue 18771: Make it possible to set the number linear probes at compile-time. (diff) | |
download | cpython-173a157e725579eec1f28f8c9d53d6761ba6c79f.tar.gz cpython-173a157e725579eec1f28f8c9d53d6761ba6c79f.tar.bz2 cpython-173a157e725579eec1f28f8c9d53d6761ba6c79f.zip |
#1565525: Add traceback.clear_frames() helper function to clear locals ref'd by a traceback
Diffstat (limited to 'Lib/traceback.py')
-rw-r--r-- | Lib/traceback.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/traceback.py b/Lib/traceback.py index 3aa1578f4e4..d5b37528bab 100644 --- a/Lib/traceback.py +++ b/Lib/traceback.py @@ -7,7 +7,8 @@ import operator __all__ = ['extract_stack', 'extract_tb', 'format_exception', 'format_exception_only', 'format_list', 'format_stack', 'format_tb', 'print_exc', 'format_exc', 'print_exception', - 'print_last', 'print_stack', 'print_tb'] + 'print_last', 'print_stack', 'print_tb', + 'clear_frames'] # # Formatting and printing lists of traceback lines. @@ -299,3 +300,13 @@ def extract_stack(f=None, limit=None): stack = list(_extract_stack_iter(_get_stack(f), limit=limit)) stack.reverse() return stack + +def clear_frames(tb): + "Clear all references to local variables in the frames of a traceback." + while tb is not None: + try: + tb.tb_frame.clear() + except RuntimeError: + # Ignore the exception raised if the frame is still executing. + pass + tb = tb.tb_next |