On 4/15/06, <b class="gmail_sendername">Manlio Perillo</b> <<a href="mailto:manlio_perillo@libero.it">manlio_perillo@libero.it</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
from twisted.internet import defer, reactor<br><br><br>def waitFor(seconds):<br> """It would be nice to have this in twisted.internet.defer.<br> Thanks to Matt Goodall.<br> """<br>
<br> d = defer.Deferred()<br> reactor.callLater(seconds, lambda: d.callback(None))<br><br> return defer.waitForDeferred(d)<br><br><br>@defer.deferredGenerator<br>def generator():<br> d = defer.waitForDeferred(
defer.succeed(1))<br> yield d<br><br> d = defer.waitForDeferred(defer.fail(Exception("error 1")))<br> yield d<br><br># raise Exception("error 2")<br><br> yield waitFor(3)</blockquote><div>
<br>You want to getResult() the result from waitFor().<br><br> </div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> d = defer.waitForDeferred
(defer.succeed(2))</blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> yield d</blockquote><div><br>You want to getResult() the result from waitForDeferred.
<br><br>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.<br></div><br></div><br>-- <br>Christopher Armstrong<br>International Man of Twistery
<br><a href="http://radix.twistedmatrix.com/">http://radix.twistedmatrix.com/</a><br><a href="http://twistedmatrix.com/">http://twistedmatrix.com/</a><br><a href="http://canonical.com/">http://canonical.com/</a><br>