[Twisted-Python] Return only when value/handle is available
Jonas Brunsgaard
jonas.brunsgaard at gmail.com
Wed Sep 3 06:40:24 MDT 2014
I would fiddle around with something like this.
from twisted.internet.defer import inlineCallbacks, returnValue, Deferred
from twisted.internet import reactor
@inlineCallbacks
def foo(self, retries=10, interval=10):
while True:
try:
returnValue((yield self.get_handle()))
except SystemDelayException as e:
if retries > 0:
retries -= 1
d = Deferred()
reactor.callLater(interval, d.callback, None)
yield d
else:
raise e
On Wed, Sep 3, 2014 at 1:32 PM, vikas kumar <vikas.c.kumar at oracle.com>
wrote:
> Hi,
>
> I am little new to twisted.
> I've a function(get_handle) which returns a handle.
>
> But get_handle() may throw an exception(SystemDelayException) because of
> some delay in system.
> My requirement is : When I get SystemDelayException re-attempt
> get_handle() and return only when handle is available. How do I use
> deferred/reactor in this scenario?
>
> try:
> handle = yield self.get_handle()
> except SystemDelayException:
> // code to re-attempt get_handle and return only when handle is
> available
>
> Regards
> Vikas
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20140903/20154e54/attachment-0002.html>
More information about the Twisted-Python
mailing list