launchpad-dev team mailing list archive
-
launchpad-dev team
-
Mailing list archive
-
Message #06788
Re: [performance] Twisted Exception "features"
John Arbash Meinel wrote:
> On 03/29/2011 08:24 AM, Andrew Bennetts wrote:
> > John Arbash Meinel wrote:
> > [...]
> >>
> >> Best case time, 350ms. Apparently those aren't the expensive exceptions.
> >> So it does help (350ms is better than 480ms.) But not as much as
> >> 'tb=None' ~180ms.
> >
> > Hmm, interesting. It might be worth patching Failure and Deferred on
> > your system to see where the other calls to Failure() [i.e. with no
> > args] are coming from. Specifically patch the part of
> > Deferred._runCallbacks that calls Failure() to say which callback
> > triggered it, and patch Failure.__init__ to report when it is called
> > without args too, because there may be some places that don't happen
> > directly in Deferred…
>
> I believe there are things like Failure.trap() and xmlrpc.trap_fault()
> that can do a bare 'raise' to re-raise the original exception because it
> doesn't match the exact type that the error handler can handle.
Neither of those is a problem, although I had to check earlier today to
be sure :)
Failure.trap() will re-raise the original Failure (it's an old-style
class, which Python allows to be raised, like how it allows you to raise
strs). Calling Failure() when the active exception is a Failure does
some magic that ends up setting self.__dict__ = raised_failure.__dict__,
so the result of Failure() in that case doesn't have self.tb set if the
original failure didn't either.
lp.services.twistedsupport.xmlrpc.trap_fault is the same: the only thing
it raises is the failure given to it (either via Failure.trap or
directly). So it's ok too.
[...]
> At least as I read that, if you pass an object for 'exc_value' but pass
> None for 'exc_tb' it will find the traceback from sys.exc_info. I have
> to actually audit the code to make sure that is the case.
I have two strong pieces of evidence that my understanding is correct.
1) my patch sped up your benchmark :)
2)
>>> from twisted.python.failure import Failure
>>> try:
... 1/0
... except ZeroDivisionError as e:
... f = Failure(e)
... f2 = Failure()
...
>>> print f.tb
None
>>> f2.tb
<traceback object at 0xb7508d4c>
-Andrew.
Follow ups
References