[Twisted-Python] how to implement sleep?
Hello Twisted is great, but how cant i emulate sleep behaviour in syested. I know that exists callLater, but how to use it in yield scenario, like here: @inlineCallbacks def work(self): l_attempts = 0; while l_attemps < 3: try: resp = yield <some twisted call> break; except: yield sleep(3); l_attempts +=1 else: log.err("cant communicate"); Here i make 3 attempts to connect busy service, with pause 3 seconds between attempts. How cant i implement this in twisted
except: l_attempts += 1 yield reactor.callLater(3, self.work) Total guess Donal On 20/09/2010, at 12:04 AM, ruslan usifov wrote:
Hello
Twisted is great, but how cant i emulate sleep behaviour in syested. I know that exists callLater, but how to use it in yield scenario, like here:
@inlineCallbacks def work(self): l_attempts = 0;
while l_attemps < 3: try: resp = yield <some twisted call> break;
except: yield sleep(3); l_attempts +=1
else: log.err("cant communicate");
Here i make 3 attempts to connect busy service, with pause 3 seconds between attempts. How cant i implement this in twisted _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
On 2010-09-19, ruslan usifov wrote:
Twisted is great, but how cant i emulate sleep behaviour in syested. I know that exists callLater, but how to use it in yield scenario, like here:
@inlineCallbacks def work(self): l_attempts = 0;
while l_attemps < 3: try: resp = yield <some twisted call> break;
except: yield sleep(3); l_attempts +=1
else: log.err("cant communicate");
Here i make 3 attempts to connect busy service, with pause 3 seconds between attempts. How cant i implement this in twisted
Perhaps you want ReconnectingClientFactory ? Set maxRetries to 3. See twisted.internet.protocols.ReconnectingClientFactory. -- Regards, Stephen Thorne Development Engineer Netbox Blue
Can you provide some code to use it? In maner like protocol.ClientCreator? Perhaps you want ReconnectingClientFactory ? Set maxRetries to 3. See
twisted.internet.protocols.ReconnectingClientFactory.
-- Regards, Stephen Thorne Development Engineer Netbox Blue
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
ruslan usifov wrote:
Hello
Twisted is great, but how cant i emulate sleep behaviour in syested. I
<http://twistedmatrix.com/documents/10.1.0/api/twisted.internet.task.deferLat...> -Andrew.
On Sun, 2010-09-19 at 22:41 +1000, Andrew Bennetts wrote:
ruslan usifov wrote:
Hello
Twisted is great, but how cant i emulate sleep behaviour in syested. I
<http://twistedmatrix.com/documents/10.1.0/api/twisted.internet.task.deferLat...>
Specifically, deferLater is a wrapper for reactor.callLater that works well with inlineCallbacks, since it returns a Deferred, so you can do "yield deferLater(reactor, 3, lambda: None)".
Hi Ruslan, Try this to drop in to your code, as in: sleep(3) def sleep(secs): d = defer.Deferred() reactor.callLater(secs, d.callback, None) return d Cheers, Luke On Sun, 2010-09-19 at 16:04 +0400, ruslan usifov wrote:
Hello
Twisted is great, but how cant i emulate sleep behaviour in syested. I know that exists callLater, but how to use it in yield scenario, like here:
@inlineCallbacks def work(self): l_attempts = 0;
while l_attemps < 3: try: resp = yield <some twisted call> break;
except: yield sleep(3); l_attempts +=1
else: log.err("cant communicate");
Here i make 3 attempts to connect busy service, with pause 3 seconds between attempts. How cant i implement this in twisted _______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- Best Regards, Luke Marsden Hybrid Logic Ltd. Web: http://www.hybrid-cluster.com/ Hybrid Web Cluster - cloud web hosting based on FreeBSD and ZFS Mobile: +447791750420
participants (6)
-
Andrew Bennetts -
Donal McMullan -
Itamar Turner-Trauring -
Luke Marsden -
ruslan usifov -
Stephen Thorne