[Python-Dev] [RFC] PEP 418: Add monotonic time, performance counter and process time functions

Victor Stinner victor.stinner at gmail.com
Sat Apr 21 02:38:35 CEST 2012


2012年4月15日 Victor Stinner <victor.stinner at gmail.com>:
>> Here is a simplified version of the first draft of the PEP 418. The
>> full version can be read online.
>> http://www.python.org/dev/peps/pep-0418/
>> FYI there is no time.thread_time() function. It would only be
> available on Windows and Linux. It does not use seconds but CPU
> cycles. No module or program of the Python source code need such
> function, whereas all other functions added by the PEP already have
> users in the Python source code, see the Rationale section. For Linux,
> CLOCK_THREAD_CPUTIME_ID is already available in Python 3.3. For
> Windows, you can get GetThreadTimes() using ctypes or win32process.

"Explicit is better than implicit" ! I listed the limitations of the
PEP directly in the PEP:
-------------
Limitations:
* The behaviour of clocks after a system suspend is not defined in the
 documentation of new functions. The behaviour depends on the
 operating system: see the `Monotonic Clocks`_ section below. Some
 recent operating systems provide two clocks, one including time
 elapsed during system suspsend, one not including this time. Most
 operating systems only provide one kind of clock.
* time.monotonic() and time.perf_counter() may or may not be adjusted.
 For example, ``CLOCK_MONOTONIC`` is slewed on Linux, whereas
 ``GetTickCount()`` is not adjusted on Windows.
 ``time.get_clock_info('monotonic')['is_adjusted']`` can be used to check
 if the monotonic clock is adjusted or not.
* No time.thread_time() function is proposed by this PEP because it is
 not needed by Python standard library nor a common asked feature.
 Such function would only be available on Windows and Linux. On
 Linux, it is possible use use
 ``time.clock_gettime(CLOCK_THREAD_CPUTIME_ID)``. On Windows, ctypes or
 another module can be used to call the ``GetThreadTimes()``
 function.
-------------
Victor


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /