[Twisted-Python] Maximum recursion depth reached
Steve Freitas
sflist at ihonk.com
Fri May 9 03:23:48 MDT 2008
Hi all,
I'm hitting the recursion limit in my code (well, somewhere inside
Twisted, that is), and I'd appreciate any insight as to why. I wouldn't
think what I'm doing -- returning a callback from method A which calls
method B, which then in turn calls method A again -- would be
controversial, since I'd assume Python would be letting go of the stack
for method A, but I guess there's more to it than that.
Code demonstrating the issue follows. Running it results in:
File "/usr/lib/python2.5/site-packages/twisted/python/reflect.py",
line 550, in accumulateBases
accumulateBases(base, l, baseClass)
exceptions.RuntimeError: maximum recursion depth exceeded
(This doesn't actually perfectly reflect my problem in the real code I'm
working with. I'm seeing "'maximum recursion depth exceeded' in <bound
method DebugInfo.__del__ of <twisted.internet.defer.DebugInfo instance
at 0xb1d99b6c>>", but I assume this is coming from the same basic
problem in my code.)
===================================
from twisted.internet import defer, reactor
def yo_print(s, d):
print s
d.callback(s)
return s
def some_deferred(item):
d = defer.Deferred()
reactor.callLater(0, lambda: yo_print(item, d))
return d
def start(items):
dl = []
for item in items:
dl.append(some_deferred(item))
if len(dl) > 4:
break
items = items[len(dl):]
if dl:
return defer.DeferredList(dl).addCallback(next_batch, items)
reactor.stop()
def next_batch(_, items):
return start(items)
if __name__ == '__main__':
items = []
for i in range(1651): # 1650 doesn't do it
items.append(i)
print start(items)
reactor.run()
===================================
So I guess the rule is to never, within a callback chain, call a
function which was invoked earlier in the callback chain?
Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20080509/8c61c829/attachment.html>
More information about the Twisted-Python
mailing list