[Twisted-Python] how to implement sleep?
Stephen Thorne
stephen at thorne.id.au
Sun Sep 19 08:35:44 EDT 2010
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
More information about the Twisted-Python
mailing list