This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: time.get_clock_info reports "adjustable=False" for implementation="CLOCK_MONOTONIC"
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Florian Krause, vstinner
Priority: normal Keywords:

Created on 2019-10-07 14:01 by Florian Krause, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg354097 - (view) Author: Florian Krause (Florian Krause) Date: 2019-10-07 14:01
clock_gettime(CLOCK_MONOTONIC) is adjustable via NTP, as described here: https://linux.die.net/man/2/clock_gettime

(and also mentioned in PEP 418).

Yet, time.get_clock_info reports it as "adjustable=False" (this even seems to be hardcoded for all clocks on Linux).
msg354099 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-10-07 14:11
Well, that's more a documentation issue than a bug.

"adjustable=False" in the context of Python means that the clock cannot jump a day forward or one day backwards.

For example, on my Fedora 30, I cannot set CLOCK_MONOTONIC clock as root:

$ sudo python3
>>> import time
>>> time.clock_settime(time.CLOCK_MONOTONIC, time.clock_gettime(time.CLOCK_MONOTONIC))
OSError: [Errno 22] Invalid argument

In the Linux kernel, NTP adjusts CLOCK_MONOTONIC so it really measures time in *seconds*, rather something faster or slower than one second :-)

Python time.monotonic() documentation clearly states that it uses the unit of one second:
https://docs.python.org/dev/library/time.html#time.monotonic
"Return the value (in fractional seconds) of a monotonic clock, i.e. a clock that cannot go backwards. (...)"

CLOCK_MONOTONIC_RAW must not be used for time.monotonic() because it doesn't use an unit of 1 second.

Feel free to propose a documentation enhancement :-)

https://docs.python.org/dev/library/time.html#time.get_clock_info
History
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82575
2019-10-07 14:11:43vstinnersetnosy: + vstinner
messages: + msg354099
2019-10-07 14:01:54Florian Krausecreate