Skip to content

Commit

Permalink
fix recursion-proofing
Browse files Browse the repository at this point in the history
patch debugged by Daniel THOMPSON <daniel.thompson@st.com>
  • Loading branch information
Dustin J. Mitchell committed Mar 7, 2010
1 parent 155fa78 commit 54f29cd
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions contrib/git_buildbot.py
Expand Up @@ -31,7 +31,7 @@

from twisted.spread import pb
from twisted.cred import credentials
from twisted.internet import reactor
from twisted.internet import reactor, defer

from optparse import OptionParser

Expand Down Expand Up @@ -59,30 +59,38 @@ def connectFailed(error):
return error


def addChange(remote, changei):
logging.debug("addChange %s, %s" % (repr(remote), repr(changei)))
try:
c = changei.next()
except StopIteration:
remote.broker.transport.loseConnection()
return None

logging.info("New revision: %s" % c['revision'][:8])
for key, value in c.iteritems():
logging.debug(" %s: %s" % (key, value))

d = remote.callRemote('addChange', c)

# tail recursion in Twisted can blow out the stack, so we
# insert a callLater to delay things
def recurseLater(x):
reactor.callLater(0, addChange, remote, changei)
d.addCallback(recurseLater)
return d
def addChanges(remote, changei):
logging.debug("addChanges %s, %s" % (repr(remote), repr(changei)))
def addChange(c):
logging.info("New revision: %s" % c['revision'][:8])
for key, value in c.iteritems():
logging.debug(" %s: %s" % (key, value))

d = remote.callRemote('addChange', c)
return d

finished_d = defer.Deferred()
def iter():
try:
c = changei.next()
d = addChange(c)
# handle successful completion by re-iterating, but not immediately
# as that will blow out the Python stack
def cb(_):
reactor.callLater(0, iter)
d.addCallback(cb)
# and pass errors along to the outer deferred
d.addErrback(finished_d.errback)
except StopIteration:
remote.broker.transport.loseConnection()
finished_d.callback(None)

iter()
return finished_d


def connected(remote):
return addChange(remote, changes.__iter__())
return addChanges(remote, changes.__iter__())


def grab_commit_info(c, rev):
Expand Down

0 comments on commit 54f29cd

Please sign in to comment.