3
# Copyright (c) 2009 Twisted Matrix Laboratories.
4
# See LICENSE for details.
6
from twisted.internet import defer
7
from twisted.python import failure, util
10
Here we have the simplest case, a single callback and a single errback.
17
print "we got an exception: %s" % (f.getTraceback(),)
20
def handleResult(result):
22
print "callback %s" % (num,)
23
print "\tgot result: %s" % (result,)
24
return "yay! handleResult was successful!"
27
def behindTheScenes(result):
28
# equivalent to d.callback(result)
30
if not isinstance(result, failure.Failure): # ---- callback
32
result = handleResult(result)
34
result = failure.Failure()
39
if not isinstance(result, failure.Failure): # ---- callback
43
result = handleFailure(result)
45
result = failure.Failure()
48
def deferredExample():
50
d.addCallback(handleResult)
51
d.addErrback(handleFailure)
56
if __name__ == '__main__':
57
behindTheScenes("success")
58
print "\n-------------------------------------------------\n"