[Twisted-Python] Accurate delays in callLater

Bob Ippolito bob at redivi.com
Thu Jun 23 11:30:19 MDT 2005


On Jun 23, 2005, at 1:13 PM, Norm Petterson wrote:

> George Sakkis wrote:
>
>
>> I'm using twisted for a realtime simulation and I'm calling
>> reactor.callLater() for scheduling actions to be performed after a  
>> fixed
>> short delay (~60msec). However, if there is a cpu-intensive procedure
>> running in the meantime, the timer for the scheduled call may  
>> expire much
>> later, an order of magnitude or more if the procedure takes too  
>> much time.
>> Is this to be expected in general ? If not, does this may have to  
>> with the
>> delay being too short or the cpu-intensive procedure being mainly  
>> run in
>> an extension module ? Finally, is there a way to force the  
>> required delay
>> (with a tolerance of a few msec) ?
>>
>
> You don't say whether the cpu-intensive procedure is a part of your  
> Twisted app (in which case it is an example of "blocking" behavior  
> that you must design to eliminate yourself), or is running outside  
> of Twisted (in which case you must utilize operating system  
> features to run your Twisted app at a higher process priority).
>
> Unlike the preemptive scheduling of real time operating systems,  
> Twisted "scheduling" won't preempt anything already running.

Additionally, the precision of reactor.callLater is only as good as  
the precision of the reactor's primitive for timing (select, in the  
default reactor).  The precision of select varies widely based on the  
platform.

You might have more luck with twisted.internet.task.LoopingCall

-bob





More information about the Twisted-Python mailing list