Robert Collins added the comment: Right, and a usable API.
I believe that this will meet Guido's use case: tb = TracebackException(*sys.exc_info, lookup_lines=False) .... some time later .... if should_show_tb: lines = list(tb.format()) I'm not 100% sold on the public API being a generator, but rather than forcing it one way or the other, I'll let reviewers tell me what they think :) Performance wise, this is better, with the following times: format_stack -> 5.19ms new API to extract and not format -> 3.06ms new API to extract, not lookup lines and not format -> 2.32ms Formatting is then 2-3ms per 500 line traceback actually formatted, which seems terribly slow, but its still better than the 8+ms trunk takes (see my earlier tests). I'll look at tuning the time to render an actual trace later, since I don't like paying high costs in unittest ;) - but AIUI this should be enough to help asyncio as is. Updated test script I used to isolate times with timeit: import traceback def recurse(count, lookup_lines=True): if count> 0: return recurse(count - 1, lookup_lines=lookup_lines) if lookup_lines: return traceback.Stack.extract(traceback.walk_stack(None), lookup_lines=True) else: return traceback.Stack.extract(traceback.walk_stack(None), lookup_lines=False) def doit(): len(recurse(500)) def doit_lazy(): len(recurse(500, False)) ---------- Added file: http://bugs.python.org/file37862/issue17911-2.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue17911> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com