Opened 10 years ago

#5269 enhancement new

recursion depth exceeded errors are reported in a confusing way in inlineCallbacks functions

Reported by: Glyph Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description

When recursion depth is exceeded in an @inlineCallbacks function, the reported error is confusing, since it ends up blowing up in the error reporting code. For example, this program:

from twisted.internet.defer import inlineCallbacks, returnValue
@inlineCallbacks
def prettyRecursive():
    returnValue((yield prettyRecursive()))
prettyRecursive()

produces this traceback:

Unhandled error in Deferred:
Unhandled Error
Traceback (most recent call last):
  File ".../twisted/internet/defer.py", line 1145, in unwindGenerator
    return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
  File ".../twisted/internet/defer.py", line 1024, in _inlineCallbacks
    result = g.send(result)
  File "icmr.py", line 4, in prettyRecursive
    returnValue((yield prettyRecursive()))
  File ".../twisted/internet/defer.py", line 1145, in unwindGenerator
    return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
--- <exception caught here> ---
  File ".../twisted/internet/defer.py", line 1024, in _inlineCallbacks
    result = g.send(result)
  File "icmr.py", line 4, in prettyRecursive
    returnValue((yield prettyRecursive()))
  File ".../twisted/internet/defer.py", line 1145, in unwindGenerator
    return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
  File ".../twisted/internet/defer.py", line 1070, in _inlineCallbacks
    deferred.errback()
  File ".../twisted/internet/defer.py", line 386, in errback
    fail = failure.Failure(captureVars=self.debug)
  File ".../twisted/python/failure.py", line 202, in __init__
    if isinstance(exc_value, (str, unicode)) and exc_type is None:
exceptions.RuntimeError: maximum recursion depth exceeded while calling a Python object

This makes it look like the error is coming out of 'isinstance'. (In this trivial example, application code is on the stack, but in some more involved cases, which I haven't figured out how to compress into a nice short snippet, the application code can be entirely gone by the time this error gets reported.)

Change History (0)

Note: See TracTickets for help on using tickets.