[Twisted-Python] deferredGenerator ad errbacks

Christopher Armstrong radix at twistedmatrix.com
Sat Apr 15 07:46:44 MDT 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)
>
>
> @defer.deferredGenerator
> 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))

    yield d


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
it.


--
Christopher Armstrong
International Man of Twistery
http://radix.twistedmatrix.com/
http://twistedmatrix.com/
http://canonical.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20060415/6b6da065/attachment.html>


More information about the Twisted-Python mailing list