Opened 10 years ago

Closed 10 years ago

#5552 defect closed duplicate (duplicate)

accurate periodic calls

Reported by: Zoran Bosnjak Owned by:
Priority: normal Milestone:
Component: core Keywords: reactor, monotonic time, looping, periodic
Cc: Branch:


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.

Attachments (1) (985 bytes) - added by Zoran Bosnjak 10 years ago.
example monotonic_time implementation

Download all attachments as: .zip

Change History (2)

Changed 10 years ago by Zoran Bosnjak

Attachment: added

example monotonic_time implementation

comment:1 Changed 10 years ago by Jean-Paul Calderone

Resolution: duplicate
Status: newclosed

Thanks for your interest and for the sample implementation. This is a duplicate of ticket #2424, though. If you want to help out in this area of Twisted, take a look at the history over there. :)

Note: See TracTickets for help on using tickets.