[Twisted-Python] sleeping in inlineCallbacks

Brian Granger ellisonbg.net at gmail.com
Thu Oct 29 10:59:58 EDT 2009


Glyph,


In general, please reply on this list inline, with quoting and trimming,
> like so:
>
>     http://en.wikipedia.org/wiki/Posting_style#Inline_replying
>
> This might seem like a minor thing, but it really helps those of us who
> have to follow long discussions and many mailing lists.
>

Sorry, just being lazy...


I have been using Twisted for years but only recently began to use
> inlineCallbacks (couldn't give up Python 2.4 support until recently).  This
> simple asynch. sleep function is fantastic.  Just today I used to it with
> inlineCallbacks to dramatically clean up some complex deferred logic.
>
>
> Which asynch sleep function?
>
>
This one posted by Paul:

def sleep(seconds):
    d = defer.Deferred()
    reactor.callLater(seconds, d.callback, seconds)
    return d

I hope you're not talking about this stuff, quoted in your message:
>
> On Wed, Oct 7, 2009 at 8:28 PM, Andrew Bennetts <andrew at bemusement.org>wrote:
>
>> >    What about Deferred.setTimeout?
>>
>
> Please note spiv's reply:
>
> Deferred.setTimeout is a poor API and is deprecated (despite what the
>> automatically generated API docs think).
>>
> and his recommendation:
>
> So please, don't use setTimeout, and definitely do not recommend it to
>> others!
>>
>
Definitely not - I did see this warning.



> I hope that, instead, you're talking about the deferLater function that was
> introduced in Twisted 8.0?
>
>
> http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.task.html#deferLater
>
> This will act like an async 'sleep' if its result is yielded from an
> @inlineCallbacks function.
>
>
I looked at deferLater, but am not using it right now.  The sleep function I
am using is basically the same as this - in my case "sleep" turned out to be
a little simpler because I don't have to create and pass the clock around.
But I will probably use deferLater for this same purpose in the future as
well.

Cheers,

Brian


>
> _______________________________________________
> 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: http://twistedmatrix.com/pipermail/twisted-python/attachments/20091029/0efad1cb/attachment.htm 


More information about the Twisted-Python mailing list