()
| 234 | |
| 235 | |
| 236 | def print_exception(): |
| 237 | import linecache |
| 238 | linecache.checkcache() |
| 239 | flush_stdout() |
| 240 | efile = sys.stderr |
| 241 | typ, val, tb = excinfo = sys.exc_info() |
| 242 | sys.last_type, sys.last_value, sys.last_traceback = excinfo |
| 243 | seen = set() |
| 244 | |
| 245 | def print_exc(typ, exc, tb): |
| 246 | seen.add(id(exc)) |
| 247 | context = exc.__context__ |
| 248 | cause = exc.__cause__ |
| 249 | if cause is not None and id(cause) not in seen: |
| 250 | print_exc(type(cause), cause, cause.__traceback__) |
| 251 | print("\nThe above exception was the direct cause " |
| 252 | "of the following exception:\n", file=efile) |
| 253 | elif (context is not None and |
| 254 | not exc.__suppress_context__ and |
| 255 | id(context) not in seen): |
| 256 | print_exc(type(context), context, context.__traceback__) |
| 257 | print("\nDuring handling of the above exception, " |
| 258 | "another exception occurred:\n", file=efile) |
| 259 | if tb: |
| 260 | tbe = traceback.extract_tb(tb) |
| 261 | print('Traceback (most recent call last):', file=efile) |
| 262 | exclude = ("run.py", "rpc.py", "threading.py", "queue.py", |
| 263 | "debugger_r.py", "bdb.py") |
| 264 | cleanup_traceback(tbe, exclude) |
| 265 | traceback.print_list(tbe, file=efile) |
| 266 | lines = get_message_lines(typ, exc, tb) |
| 267 | for line in lines: |
| 268 | print(line, end='', file=efile) |
| 269 | |
| 270 | print_exc(typ, val, tb) |
| 271 | |
| 272 | def cleanup_traceback(tb, exclude): |
| 273 | "Remove excluded traces from beginning/end of tb; get cached lines" |
no test coverage detected