14.03.2013, в 18:20, exar...@twistedmatrix.com написал(а):
> On 09:40 am, ser...@gmail.com wrote: >> Hello to all! >> >> Why traceback doesn't include call of g() here? > > Tracebacks are tricky, and inlineCallbacks doesn't make them look > exactly like they would look if you didn't have Deferreds. > > twisted.python.failure is a little bit better at handling tracebacks > from this sort of code than the traceback module is, so if you write the > code like this things will at least be a little better: > > from twisted.python.failure import Failure > > def decor1(): > try: > res = yield f(*argv, **kw) > except: > Failure.printTraceback() > else: > defer.returnValue(res) How can I catch failure? In your example you call printTraceback as classmethod but it is instance one. > Notice also that I moved returnValue outside of the try block. > `returnValue` is implemented using exceptions, so you *must not* catch > and handle the exception it raises or it won't work. Thanks for that detail! > > Jean-Paul >> import traceback >> from twisted.internet import defer, reactor >> >> def decor1(f, *argv, **kw): >> @defer.inlineCallbacks >> def decor1(): >> try: >> res = yield f(*argv, **kw) >> defer.returnValue(res) >> except: >> traceback.print_exc() >> return decor1 >> >> @defer.inlineCallbacks >> def g(): >> raise AttributeError >> yield defer.succeed(1) >> >> @decor1 >> @defer.inlineCallbacks >> def f(): >> yield g() >> >> f() >> reactor.run() >> >> I see just: >> Traceback (most recent call last): >> File "C:\testing\test.py", line 9, in decor1 >> res = yield f(*argv, **kw) >> AttributeError >> >> >> >> _______________________________________________ >> Twisted-Python mailing list >> Twisted-Python@twistedmatrix.com >> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python > > _______________________________________________ > Twisted-Python mailing list > Twisted-Python@twistedmatrix.com > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python