<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.18.1">
</HEAD>
<BODY>
Hi all,<BR>
<BR>
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.<BR>
<BR>
Code demonstrating the issue follows. Running it results in:<BR>
File "/usr/lib/python2.5/site-packages/twisted/python/reflect.py", line 550, in accumulateBases<BR>
accumulateBases(base, l, baseClass)<BR>
exceptions.RuntimeError: maximum recursion depth exceeded<BR>
<BR>
(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.)<BR>
<BR>
===================================<BR>
<BR>
from twisted.internet import defer, reactor<BR>
<BR>
def yo_print(s, d):<BR>
print s<BR>
d.callback(s)<BR>
return s<BR>
<BR>
def some_deferred(item):<BR>
d = defer.Deferred()<BR>
reactor.callLater(0, lambda: yo_print(item, d))<BR>
return d<BR>
<BR>
def start(items):<BR>
dl = []<BR>
for item in items:<BR>
dl.append(some_deferred(item))<BR>
if len(dl) > 4:<BR>
break<BR>
items = items[len(dl):]<BR>
if dl:<BR>
return defer.DeferredList(dl).addCallback(next_batch, items)<BR>
reactor.stop()<BR>
<BR>
def next_batch(_, items):<BR>
return start(items)<BR>
<BR>
if __name__ == '__main__':<BR>
items = []<BR>
for i in range(1651): # 1650 doesn't do it<BR>
items.append(i)<BR>
print start(items)<BR>
reactor.run()<BR>
<BR>
===================================<BR>
<BR>
So I guess the rule is to never, within a callback chain, call a function which was invoked earlier in the callback chain?<BR>
<BR>
Steve
</BODY>
</HTML>