Message234712
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)) |
|
Date |
User |
Action |
Args |
2015-01-26 03:18:48 | rbcollins | set | recipients:
+ rbcollins, gvanrossum, rhettinger, ncoghlan, pitrou, vstinner, eric.snow, yselivanov, adaptivelogic |
2015-01-26 03:18:47 | rbcollins | set | messageid: <1422242327.72.0.776642448174.issue17911@psf.upfronthosting.co.za> |
2015-01-26 03:18:47 | rbcollins | link | issue17911 messages |
2015-01-26 03:18:46 | rbcollins | create | |
|