classification
Title: clarify "may not" in time.steady docs
Type: enhancement Stage:
Components: Documentation Versions: Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jim.Jewett, docs@python, vstinner
Priority: normal Keywords:

Created on 2012-03-15 15:38 by Jim.Jewett, last changed 2012-04-04 22:07 by vstinner. This issue is now closed.

Messages (6)
msg155907 - (view) Author: Jim Jewett (Jim.Jewett) (Python triager) Date: 2012-03-15 16:41
http://docs.python.org/dev/library/time.html#time.steady

Current:
"""Return the current time as a floating point number expressed in seconds. This clock advances at a steady rate relative to real time and it may not be adjusted. The reference point of the returned value is undefined so only the difference of consecutive calls is valid.

If available, a monotonic clock is used. By default, if strict is False, the function falls back to another clock if the monotonic clock failed or is not available. If strict is True, raise an OSError on error or NotImplementedError if no monotonic clock is available."""

Does "may not" mean that the user isn't allowed to adjust it, or that they system won't always have adjusted it?  Assuming that this really means it won't jump around for daylight savings time or manual time resets, it could be reworded as:



"""Return elapsed seconds as a floating point number.  The start time is undefined, so only differences between calls are meaningful.  steady() is the best clock for profiling response time, as opposed to CPU usage.

This function prefers to rely upon a high-precision counter that is not affected by resetting the system time.  If no such monotonic clock is available, steady() will substitute another clock, but steady(strict=true) will raise either NotImplementedError or OSError.  """
msg156333 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-03-19 12:21
> Does "may not" mean that the user isn't allowed to adjust it,
> or that they system won't always have adjusted it?

It depends on which clock is used.

 - clock_gettime(CLOCK_MONOTONIC_RAW) cannot be adjusted
 - clock_gettime(CLOCK_MONOTONIC) can be adjusted by NTP (only its speed, no forward or backward jump)
 - I don't think that QueryPerformanceCounter() can be adjusted
 - gettimeofday(), ftime() and time() are the system clock and can be changed manually by the system administrator or automatically by NTP (maybe with a jump, forward or backward)
 - clock() is used on Windows if QueryPerformanceFrequency failed. I donk't know if it can be ajdusted

It is important to mention that time.steady() may be adjusted in some cases.
msg156336 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-03-19 12:48
FYI "may not" comes from the C++ Timeout Specification:

"Objects of class steady_clock represent clocks for which values of time_point never decrease as physical time advances and for which values of time_point advance at a steady rate relative to real time. That is, the clock may not be adjusted."

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3191.htm
msg156679 - (view) Author: Jim Jewett (Jim.Jewett) (Python triager) Date: 2012-03-23 22:38
(1)  How does the user control (or even find out) which clock is used by time.steady()?

If the answer is time.steady(clock=QueryPerformanceCounter) then there is no need for strict=?, but then I'm not sure what the point of time.steady itself is.

I had been assuming that time.steady() relied on the best clock it could find, which shouldn't normally change on a specific machine, let alone within a single process.  In that case, exposing the actual clock (or its name) as an attribute seems better than a boolean "complain_if_my_machine_is_not_good_enough" parameter.


(2)  That fragment from the C++ standard suggests that "MAY NOT" ought to have been replaced by the unambiguous "MUST NOT".  I do not think that python should repeat the editorial error.

(3)  Even leaving aside the question of which clock is actually provided, I still prefer a change in wording.  My trailing paragraph might change with the API, but the rationale for:

"""Return elapsed seconds as a floating point number.  

The start time is undefined, so only differences between calls are meaningful.  steady() is the best clock for profiling response time, as opposed to CPU usage.
"""

includes:

"elapsed" ==> time since something, as opposed to absolute time.  

If practicality and efficiency weren't important, I would even suggest that the function return an opaque object that supported only ordering and subtraction (returning a timedelta).

There are enough time-related modules/classes/functions/etc that people *will* get confused; the name "steady" isn't obvious enough. Including the intended use case in the docstring gives people a fighting chance.
msg156680 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-03-23 23:40
> (2)  That fragment from the C++ standard suggests that "MAY NOT" ought to have been replaced by the unambiguous "MUST NOT".

No. A program cannot deny the modification of system clock and time.steady() may use the system date.
msg157513 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-04-04 22:07
I close this issue as a duplicate because it is now discussed in the PEP 418 and this PEP is going to change the new time functions (time.highres and time.monotonic/steady).
History
Date User Action Args
2012-04-04 22:07:15vstinnersetstatus: open -> closed
resolution: duplicate
messages: + msg157513
2012-03-23 23:40:31vstinnersetmessages: + msg156680
2012-03-23 22:38:17Jim.Jewettsetmessages: + msg156679
2012-03-19 12:48:35vstinnersetmessages: + msg156336
2012-03-19 12:21:52vstinnersetmessages: + msg156333
2012-03-16 14:40:39eric.araujosetnosy: + vstinner
2012-03-15 16:41:08Jim.Jewettsetmessages: + msg155907
title: clarify http://docs.python.org/dev/library/time.html#time.steady -> clarify "may not" in time.steady docs
2012-03-15 15:38:21Jim.Jewettcreate