Ticket #5854 enhancement new
When inlineCallbacks is used at multiple stacks levels, tracebacks don't show these levels.
| Reported by: | talljosh | Owned by: | talljosh |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | core | Keywords: | |
| Cc: | Branch: | branches/inlinecallacks-traceback-info-5854-2 | |
| Author: | talljosh, exarkun | Launchpad Bug: |
Description
Potentially similar tickets: #3622, #5178
Simple example code that creates a call stack using inlineCallbacks and causes an error at the bottom level:
# This example creates a call stack that uses inlineCallbacks and causes an error at the bottom level.
from twisted.internet import defer, reactor
@defer.inlineCallbacks
def a():
yield 1/0
@defer.inlineCallbacks
def b():
yield a()
@defer.inlineCallbacks
def c():
yield b()
def main():
d = c()
@d.addErrback
def caught(x):
x.printTraceback()
reactor.stop()
if __name__ == '__main__':
reactor.callWhenRunning(main)
reactor.run()
The resulting traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/Twisted-11.0.0-py2.7-linux-i686.egg/twisted/internet/defer.py", line 1141, in unwindGenerator
return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
File "/usr/local/lib/python2.7/dist-packages/Twisted-11.0.0-py2.7-linux-i686.egg/twisted/internet/defer.py", line 1020, in _inlineCallbacks
result = g.send(result)
File "simpletwistedtest.py", line 9, in b
yield a()
File "/usr/local/lib/python2.7/dist-packages/Twisted-11.0.0-py2.7-linux-i686.egg/twisted/internet/defer.py", line 1141, in unwindGenerator
return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
--- <exception caught here> ---
File "/usr/local/lib/python2.7/dist-packages/Twisted-11.0.0-py2.7-linux-i686.egg/twisted/internet/defer.py", line 1020, in _inlineCallbacks
result = g.send(result)
File "simpletwistedtest.py", line 5, in a
yield 1/0
exceptions.ZeroDivisionError: integer division or modulo by zero
I've created a patch that inserts frames into the failure object to given something more useful:
Traceback (most recent call last):
File "twistedtest.py", line 171, in unwindGenerator
return _inlineCallbacks(None, f(*args, **kwargs), defer.Deferred())
File "twistedtest.py", line 27, in _inlineCallbacks
result = g.send(result)
File "twistedtest.py", line 183, in b
yield a()
File "twistedtest.py", line 171, in unwindGenerator
return _inlineCallbacks(None, f(*args, **kwargs), defer.Deferred())
--- <exception caught here> ---
File "twistedtest.py", line 187, in c
yield b()
File "twistedtest.py", line 183, in b
yield a()
File "twistedtest.py", line 27, in _inlineCallbacks
result = g.send(result)
File "twistedtest.py", line 179, in a
yield 1/0
exceptions.ZeroDivisionError: integer division or modulo by zero
I intend to submit the patch as soon as I've got some good tests for the code.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

