[Twisted-Python] accurate periodic call
solipsis at pitrou.net
Mon Feb 20 05:21:08 EST 2012
On Sun, 19 Feb 2012 16:49:23 +0000
Zoran Bošnjak <Zoran.Bosnjak at sloveniacontrol.si> wrote:
> Hello all,
> I was astonished to find out that looping call period depends on the system time by default. The periodic tick can even stall for a long time, if the system time jumps backwards during program execution. It turned out that this is in fact a python problem (not providing a monotonic time, at least not for posix).
> I urgently need accurate periodic call in my program and I've found the solution below that seems to be working. I kindly ask you for your comments:
> - Is this monotonic_time implementation OK from python perspective?
For the record:
You'll have to fallback on the normal time when clock_gettime() fails
(which can happen if there is a mismatch between glibc version and
kernel version, for example).
clock_gettime() is a POSIX standard so you probably shouldn't use a
Linux-specific magic value for CLOCK_MONOTONIC.
More information about the Twisted-Python