Hello Colleagues: >For ticket 1138 (cool movie), when I access the URL: >http://twistedmatrix.com/projects/core/documentation/howto/tutorial/deferred_tutorial.html >I get, URL not found. Which deferred tutorial are you referring to? >>"Deferreds are Beautiful (A Tutorial) at : >http://twistedmatrix.com/projects/core/documentation/howto/deferredindepth.html. >I see the reference to python.util there.
Looking at Ticket 1138. Again, I believe the ticket should be referring to the deferredindepth.html document "Deferreds are Beautiful." To answer the question: no you do not need python.util. I also put a minor correction in deferred_ex.py to get rid of the syntax warning in line 57. Cheers, Andrew
#!/usr/bin/python from twisted.internet import defer from twisted.python import failure """ here we have the simplest case, a single callback and a single errback """ def handleFailure(f): print "errback" print "we got an exception: %s" % (f.getTraceback(),) f.trap(RuntimeError) def handleResult(result): global num num += 1 print "callback %s" % (num,) print "\tgot result: %s" % (result,) return "yay! handleResult was successful!" def behindTheScenes(result): # equivalent to d.callback(result) if not isinstance(result, failure.Failure): # ---- callback try: result = handleResult(result) except: result = failure.Failure() else: # ---- errback pass if not isinstance(result, failure.Failure): # ---- callback pass else: # ---- errback try: result = handleFailure(result) except: result = failure.Failure() def deferredExample(): d = defer.Deferred() d.addCallback(handleResult) d.addErrback(handleFailure) d.callback("success") if __name__ == '__main__': global num num = 0 behindTheScenes("success") print "\n-------------------------------------------------\n" deferredExample()
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python