from twisted.internet import reactor, defer
def getDummyData(x):
"""
This function is a dummy which simulates a delayed result and
returns a Deferred which will fire with that result. Don't try too
hard to understand this.
"""
d = defer.Deferred()
# simulate a delayed result by asking the reactor to fire the
# Deferred in 2 seconds time with the result x * 3
reactor.callLater(2, d.callback, x * 3)
return d
def printData(d):
"""
Data handling function to be added as a callback: handles the
data by printing the result
"""
raise ValueError('IIIGGAA')
print d
def nextCall(d):
import pdb; pdb.set_trace()
d = getDummyData(3)
d.addErrback(nextCall).addCallback(printData).addErrback(nextCall).addCallback(nextCall)
# manually set up the end of the process by asking the reactor to
# stop itself in 4 seconds time
reactor.callLater(1, reactor.stop)
# start up the Twisted reactor (event loop handler) manually
reactor.run()
function nextCall - never calls. So were I can find my ValueError?
Thanks.
It's never called because the code under your comment that says it asks the reactor to stop itself in 4 seconds actually asks the reactor to stop itself in 1 second. The 2-second callLater
never gets called, so d
is never fired, so nextCall
is never called.
Maybe you should try constructing this example without use of the reactor, just by calling callback
on the appropriate deferred synchronously? You don't need the reactor to fire a simple Deferred
and messing around with them synchronously can help to give you a more precise idea of what exactly happens when.