[Twisted-Python] Accurate delays in callLater
exarkun at divmod.com
Thu Jun 23 15:44:47 EDT 2005
On Thu, 23 Jun 2005 12:34:41 -0700, Ian Duggan <ian at ianduggan.net> wrote:
>On Thursday 23 June 2005 11:27, Norm Petterson wrote:
>> I've been using twisted.internet.task.LoopingCall for applications
>> calling for 1 second (or 2 second, or 10 second, etc.) indefinite
>> repetition for the past year, and have noted minor slippage that I
>> attribute to *not* bumping the twisted application process priority
>> above its default on the platforms involved (Linux/DEC Alpha, W2K/Intel
>> P4). If the slippage were unacceptable, I'd try raising process priority
>> before anything else...
>Another idea is to do the bookkeeping yourself.
>1) Schedule something to wake up periodically. The period would depend on your
>desired level of smoothness.
>2) Have it perform your task.
>3) If it notices that things are slipping (numer exectutions < number expected
>excutions) based on time.time(), it can run your operation however many times
>it needs to catch up.
This is precisely what LoopingCall does.
I'd be interested to hear more details about cases where LoopingCall does allow slippage. As far as I know, there is no room for improvement here: the only thing that could cause it to slip is if the system clock were not maintaining time correctly, and in that case I believe you are pretty much screwed on anything time related (okay, maybe not, I guess you could have an NTP implementation and schedule things against that, rather than the system clock...)
More information about the Twisted-Python