[Twisted-Python] accurate periodic call
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?
- Is monkey patch to the reactor OK or is there any other solution more appropriate in this case (I do not want to patch each looping call, but once in the application)?
- Does this patch have any negative influence to the rest of the reactor?
- How would you implement a periodic function call in twisted application (as accurate as possible)?
- Any chance to see something implemented inside twisted and/or python, so that applications don't need this kind of tricks?
Thanks a lot for your comments.
Zoran
#! /usr/bin/env python
from twisted.internet import task
from twisted.internet import reactor
import os
import time
import ctypes
# python MONOTONIC time, borrowed here
# http://stackoverflow.com/questions/1205722/how-do-i-get-monotonic-time-durat...
if os.name == 'posix':
CLOCK_MONOTONIC = 1 # see
participants (8)
-
Antoine Pitrou
-
exarkun@twistedmatrix.com
-
gelin yan
-
Glyph
-
Itamar Turner-Trauring
-
Phil Mayers
-
Tristan Seligmann
-
Zoran Bošnjak