Author rbcollins
Recipients adaptivelogic, eric.snow, gvanrossum, ncoghlan, pitrou, rbcollins, rhettinger, vstinner, yselivanov
Date 2015-01-26.03:18:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1422242327.72.0.776642448174.issue17911@psf.upfronthosting.co.za>
In-reply-to
Content
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))
History
Date User Action Args
2015-01-26 03:18:48rbcollinssetrecipients: + rbcollins, gvanrossum, rhettinger, ncoghlan, pitrou, vstinner, eric.snow, yselivanov, adaptivelogic
2015-01-26 03:18:47rbcollinssetmessageid: <1422242327.72.0.776642448174.issue17911@psf.upfronthosting.co.za>
2015-01-26 03:18:47rbcollinslinkissue17911 messages
2015-01-26 03:18:46rbcollinscreate