accurate periodic calls
|Reported by:||zoranbosnjak||Owned by:|
|Component:||core||Keywords:||reactor, monotonic time, looping, periodic|
Twisted reactor uses python's time.time() to handle time intervals and periodic calls.
On posix (on python 2.7), this provides incorrect behaviour if the system time changes during program execution. At this situation, all pending time calculations are wrong by this time jump (which can be huge). So the program would yield completely wrong timing responses or might even stall.
The reactor shall (by default) not depend on system time, but instead on some form of monotonic time.
To workaround the problem, an application can do something like this:
from twisted.internet import reactor
from monotonic_time import monotonic_time
reactor.seconds = monotonic_time
Example monotonic_time implementation is attached for posix platform. Not sure about other platforms.
I recommend to include monotonic time as default behaviour of the reactor.