@@ -128,8 +128,11 @@ def format_exception_only(etype, value):
128128def print_exc (limit = None , file = None ):
129129 if not file :
130130 file = sys .stderr
131- print_exception (sys .exc_type , sys .exc_value , sys .exc_traceback ,
132- limit , file )
131+ try :
132+ etype , value , tb = sys .exc_info ()
133+ print_exception (etype , value , tb , limit , file )
134+ finally :
135+ etype = value = tb = None
133136
134137def print_last (limit = None , file = None ):
135138 if not file :
@@ -143,26 +146,23 @@ def print_stack(f=None, limit=None, file=None):
143146 try :
144147 raise ZeroDivisionError
145148 except ZeroDivisionError :
146- tb = sys .exc_traceback
147- f = tb .tb_frame .f_back
149+ f = sys .exc_info ()[2 ].tb_frame .f_back
148150 print_list (extract_stack (f , limit ), file )
149151
150152def format_stack (f = None , limit = None ):
151153 if f is None :
152154 try :
153155 raise ZeroDivisionError
154156 except ZeroDivisionError :
155- tb = sys .exc_traceback
156- f = tb .tb_frame .f_back
157- return format_list (extract_stack (t , limit ))
157+ f = sys .exc_info ()[2 ].tb_frame .f_back
158+ return format_list (extract_stack (f , limit ))
158159
159160def extract_stack (f = None , limit = None ):
160161 if f is None :
161162 try :
162163 raise ZeroDivisionError
163164 except ZeroDivisionError :
164- tb = sys .exc_traceback
165- f = tb .tb_frame .f_back
165+ f = sys .exc_info ()[2 ].tb_frame .f_back
166166 if limit is None :
167167 if hasattr (sys , 'tracebacklimit' ):
168168 limit = sys .tracebacklimit
0 commit comments