@@ -108,18 +108,20 @@ def format_stack_from_frame(fr, add_summary=False, **kwargs):
108108
109109
110110def format_exc_info (etype , evalue , tb , style = 'plaintext' , add_summary = 'auto' ,
111- reverse = False , ** kwargs ):
111+ reverse = False , suppressed_exceptions = [KeyboardInterrupt ],
112+ ** kwargs ):
112113 """
113114 Format an exception traceback, including the exception message
114115
115- keyword args like stackprinter.format()
116+ see stackprinter.format() for docs about the keyword arguments
116117 """
117118 msg = ''
118119 try :
119- # First, recursively format any chained exceptions (exceptions during whose handling
120- # the given one happened).
121- # TODO: refactor this whole messy function to return a more... structured datastructure
122- # before assembling a string, so that e.g. a summary of the whole chain can be shown at
120+ # First, recursively format any chained exceptions (exceptions
121+ # during whose handling the given one happened).
122+ # TODO: refactor this whole messy function to return a
123+ # more... structured datastructure before assembling a string,
124+ # so that e.g. a summary of the whole chain can be shown at
123125 # the end.
124126 context = getattr (evalue , '__context__' , None )
125127 cause = getattr (evalue , '__cause__' , None )
@@ -152,30 +154,37 @@ def format_exc_info(etype, evalue, tb, style='plaintext', add_summary='auto',
152154 msg += clr % chain_hint
153155
154156 # Now, actually do some formatting:
155- msgs = []
157+ parts = []
156158 if tb :
157159 frameinfos = [ex .get_info (tb_ ) for tb_ in _walk_traceback (tb )]
158- stack_msg = format_stack (frameinfos , style = style , reverse = reverse , ** kwargs )
159- msgs .append (stack_msg )
160+ if suppressed_exceptions and etype in suppressed_exceptions :
161+ summary = format_summary (frameinfos , style = style ,
162+ reverse = reverse , ** kwargs )
163+ parts = [summary ]
164+ else :
165+ whole_stack = format_stack (frameinfos , style = style ,
166+ reverse = reverse , ** kwargs )
167+ parts .append (whole_stack )
160168
161- if add_summary == 'auto' :
162- add_summary = stack_msg .count ('\n ' ) > 50
169+ if add_summary == 'auto' :
170+ add_summary = whole_stack .count ('\n ' ) > 50
163171
164- if add_summary :
165- summ = format_summary (frameinfos , style = style , reverse = reverse , ** kwargs )
166- summ += '\n '
167- msgs .append ('---- (full traceback below) ----\n \n ' if reverse else
168- '---- (full traceback above) ----\n ' )
169- msgs .append (summ )
172+ if add_summary :
173+ summary = format_summary (frameinfos , style = style ,
174+ reverse = reverse , ** kwargs )
175+ summary += '\n '
176+ parts .append ('---- (full traceback below) ----\n \n ' if reverse else
177+ '---- (full traceback above) ----\n ' )
178+ parts .append (summary )
170179
171180 exc = format_exception_message (etype , evalue , style = style )
172- msgs .append ('\n \n ' if reverse else '' )
173- msgs .append (exc )
181+ parts .append ('\n \n ' if reverse else '' )
182+ parts .append (exc )
174183
175184 if reverse :
176- msgs = reversed (msgs )
185+ parts = reversed (parts )
177186
178- msg += '' .join (msgs )
187+ msg += '' .join (parts )
179188
180189 except Exception as exc :
181190 import os
0 commit comments