Skip to main content

A framework to present system clocks by feature, intended to avoid the library-as-policy pitfalls of the discussion around PEP 418.

My 2c:

Class BaseClock

A BaseClock is the private base class of clock objects.

A clock has the following mandatory attributes:

  • .flags: Feature flags describing the clock.

A clock may have the following optional attributes:

  • .epoch: If present, the offset from time.time()'s epoch of this clock's epoch(). Not all clocks have epochs; some measure elapsed time from an unknown point and only the difference in two measurements is useful.
  • .resolution: The resolution of the underlying clock facility's reporting units. The clock can never be more precise than this value. The actual accuracy of the reported time may vary with adjustments and the real accuracy of the underlying OS clock facility (which in turn may be dependent on the precision of some hardware clock).

A clock must also supply the following methods:

  • .now(): Report the current time in seconds, a float.

Class ClockEntry

MRO: builtins.tuple
ClockEntry(flags, factory)

Class ClockFlags

MRO: builtins.int
An int with human friendly str() and repr() for clock flags.

The flag names are:

  • HIGHRES: clock with the highest resolution.
  • MONOTONIC: clock does not go backwards.
  • STEADY: clock with high stability and relatively high accuracy and precision.
  • ADJUSTED: clock whose value may be changed to the correct time.
  • WALLCLOCK: what the clock on the wall shows.
  • RUNTIME: clock based on the process running time.
  • SYNTHETIC: clock computed from other clocks, such as a monotonic clock computed from other nonmonotonic clocks.

Function get_clock(flags=0, clocklist=None)

Return a clock based on the supplied flags. The returned clock shall have all the requested flags. If no clock matches, return None.

Function get_clocks(flags=0, clocklist=None)

Yield all clocks matching the supplied flags. The returned clocks shall have all the requested flags.

Function highres()

Return the current time according to the default high resolution clock.

Function highres_clock(other_flags=0)

Return a high resolution clock, preferably steady.

Function monotonic()

Return the current time according to the default monotonic clock.

Function monotonic_clock(other_flags=0)

Return a monotonic clock, preferably high resolution.

Function steady()

Return the current time according to the default steady clock.

Function steady_clock(other_flags=0)

Return a steady clock, preferably high resolution.

Class SyntheticMonotonic

MRO: BaseClock
An example synthetic clock.

This class comes after time.time() because I think synthetic clocks should be less desired - they tend to have side effects; but perhaps offered anyway because they can offer flag combinations not always presented by the system clocks.

A simple synthetic monotonic clock may skew with respect to other instances. Steven D'Aprano wrote a better one.

Release files for cs.clockutils 20190101

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs.clockutils 20190101
File Size Uploaded
cs.clockutils-20190101.tar.gz 6.0 kB Details

Release files / cs.clockutils-20190101.tar.gz

Download URL cs.clockutils-20190101.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
df414bb2fad45446b28981cac5033b5c294539b4925246e87c603eca5c6f0393
BLAKE2b-256 checksum
How to use checksums
38d6191f87f18cc22c88e7c2fa1bd2b48428d6ad5e6b9ae6d68411f698ae829c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.6

Release history Release notifications | RSS feed

This release

20190101 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page