[Twisted-Python] deferredGenerator ad errbacks
radix at twistedmatrix.com
Sat Apr 15 09:46:44 EDT 2006
On 4/15/06, Manlio Perillo <manlio_perillo at libero.it> wrote:
> from twisted.internet import defer, reactor
> def waitFor(seconds):
> """It would be nice to have this in twisted.internet.defer.
> Thanks to Matt Goodall.
> d = defer.Deferred()
> reactor.callLater(seconds, lambda: d.callback(None))
> return defer.waitForDeferred(d)
> def generator():
> d = defer.waitForDeferred(defer.succeed(1))
> yield d
> d = defer.waitForDeferred(defer.fail(Exception("error 1")))
> yield d
> # raise Exception("error 2")
> yield waitFor(3)
You want to getResult() the result from waitFor().
d = defer.waitForDeferred(defer.succeed(2))
You want to getResult() the result from waitForDeferred.
getResult() is the thing that (either returns a result or) raises any
exceptions that a Deferred has failed with, so it's important to always call
International Man of Twistery
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Twisted-Python