Precise timing in Python?

Tim Roberts timr at probo.com
Wed Nov 15 01:21:13 EST 2000


"Bror Johansson" <bror.johansson at esavionics.se> wrote:
>
>I'm considering to use Python for an application that shall - among other
>things - stimulate some external equipment (via an I/O-card on the PCI-bus)
>with a frequency of 10 Hz.
>
>This frequency should be kept very close to 10 Hz, i.e. in the long run (~10
>hours or so) it must average to 10 +- 0.05 Hz.
>
>The 'distance' between any two consecutive 'ticks' shall be 0.1 +- 0.03
>seconds.
>
>I think signal.alarm() is not good enough, is it?.
>
>Could 'stackless python' with microthreads be a viable option?
>
>Are there any other possibilities, or do I have to abandon Python for this
>application?

Python is not your problem.  The problem is the underlying operating
system.  Most of the operating systems on which Python runs have no
performance guarantees at all.  This includes Linux and Windows.  If a
failure to maintain your specifications results in damage or injury (and
given your domain -- esavionics.se -- I'm guessing it might), then you need
to investigate real-time operating systems, or at least real-time
extensions.

You're asking for 0.5% accuracy.  Even the crystal oscillators on the
average motherboard do not maintain that accuracy.  If you really need 10
+/- 0.05 Hz average, then you should be using a piece of hardware with a
timebase of known precision.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list