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