Opened 3 years ago

Closed 3 years ago

#5552 defect closed duplicate (duplicate)

accurate periodic calls

Reported by: zoranbosnjak Owned by:
Priority: normal Milestone:
Component: core Keywords: reactor, monotonic time, looping, periodic
Cc: Branch:
Author: Launchpad Bug:

Description

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)

monotonic_time.py (985 bytes) - added by zoranbosnjak 3 years ago.
example monotonic_time implementation

Download all attachments as: .zip

Change History (2)

Changed 3 years ago by zoranbosnjak

example monotonic_time implementation

comment:1 Changed 3 years ago by exarkun

  • Resolution set to duplicate
  • Status changed from new to closed

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.