mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
#1565525: Add traceback.clear_frames() helper function to clear locals ref'd by a traceback
This commit is contained in:
parent
8408dc581e
commit
173a157e72
5 changed files with 62 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue