Re: [Twisted-Python] Return only when value/handle is available

2014-09-03 Thread Jonas Brunsgaard
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.ku...@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@twistedmatrix.com
 http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Return only when value/handle is available

2014-09-03 Thread Adi Roiban
One option in which we have both reactor and deferred :)

def do_low_level_stuff(deferred)
try:
deferred.callback(self.get_handle())
except SystemDelayException:
reactor.callLater(1, do_low_level_stuff, deferred)

def do_stuff():
deferred = Deferred()
do_low_level_stuff(deferred)
return deferred

Cheers

On 3 September 2014 12:32, vikas kumar vikas.c.ku...@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@twistedmatrix.com
 http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python



-- 
Adi Roiban

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Return only when value/handle is available

2014-09-03 Thread vikas kumar

Hi Jonas,

This is nice.
But still we are retrying it repeatedly at regular interval(10). Can't 
we get the notified asynchronously as and when handle is available.


Regards
Vikas

On 9/3/2014 6:10 PM, Jonas Brunsgaard wrote:

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.ku...@oracle.com 
mailto:vikas.c.ku...@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@twistedmatrix.com
mailto:Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python




___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python


Re: [Twisted-Python] Return only when value/handle is available

2014-09-03 Thread exarkun

On 05:52 pm, vikas.c.ku...@oracle.com wrote:

Hi Jonas,

This is nice.
But still we are retrying it repeatedly at regular interval(10). Can't 
we get the notified asynchronously as and when handle is available.


You tell us.  What's a handle?  Where do you get it from?  Does that 
system produce an event when it is ready?


Jean-Paul

___
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python