Kaydet (Commit) 2b89fdf7 authored tarafından Victor Stinner's avatar Victor Stinner

PEP 418: Rename adjusted attribute to adjustable in time.get_clock_info() result

Fix also its value on Windows and Linux according to its documentation:
"adjustable" indicates if the clock *can be* adjusted, not if it is or was
adjusted.

In most cases, it is not possible to indicate if a clock is or was adjusted.
üst bda4b880
...@@ -255,8 +255,8 @@ The module defines the following functions and data items: ...@@ -255,8 +255,8 @@ The module defines the following functions and data items:
The result has the following attributes: The result has the following attributes:
- *adjusted*: ``True`` if the clock can be adjusted (e.g. by a NTP daemon), - *adjustable*: ``True`` if the clock can be changed automatically (e.g. by
``False`` otherwise a NTP daemon) or manually by the system administrator, ``False`` otherwise
- *implementation*: The name of the underlying C function used to get - *implementation*: The name of the underlying C function used to get
the clock value the clock value
- *monotonic*: ``True`` if the clock cannot go backward, - *monotonic*: ``True`` if the clock cannot go backward,
......
...@@ -26,7 +26,7 @@ typedef struct { ...@@ -26,7 +26,7 @@ typedef struct {
typedef struct { typedef struct {
const char *implementation; const char *implementation;
int monotonic; int monotonic;
int adjusted; int adjustable;
double resolution; double resolution;
} _Py_clock_info_t; } _Py_clock_info_t;
......
...@@ -32,14 +32,14 @@ class TimeTestCase(unittest.TestCase): ...@@ -32,14 +32,14 @@ class TimeTestCase(unittest.TestCase):
info = time.get_clock_info('time') info = time.get_clock_info('time')
self.assertFalse(info.monotonic) self.assertFalse(info.monotonic)
if sys.platform != 'win32': if sys.platform != 'win32':
self.assertTrue(info.adjusted) self.assertTrue(info.adjustable)
def test_clock(self): def test_clock(self):
time.clock() time.clock()
info = time.get_clock_info('clock') info = time.get_clock_info('clock')
self.assertTrue(info.monotonic) self.assertTrue(info.monotonic)
self.assertFalse(info.adjusted) self.assertFalse(info.adjustable)
@unittest.skipUnless(hasattr(time, 'clock_gettime'), @unittest.skipUnless(hasattr(time, 'clock_gettime'),
'need time.clock_gettime()') 'need time.clock_gettime()')
...@@ -372,9 +372,9 @@ class TimeTestCase(unittest.TestCase): ...@@ -372,9 +372,9 @@ class TimeTestCase(unittest.TestCase):
info = time.get_clock_info('monotonic') info = time.get_clock_info('monotonic')
self.assertTrue(info.monotonic) self.assertTrue(info.monotonic)
if sys.platform == 'linux': if sys.platform == 'linux':
self.assertTrue(info.adjusted) self.assertTrue(info.adjustable)
else: else:
self.assertFalse(info.adjusted) self.assertFalse(info.adjustable)
def test_perf_counter(self): def test_perf_counter(self):
time.perf_counter() time.perf_counter()
...@@ -390,7 +390,7 @@ class TimeTestCase(unittest.TestCase): ...@@ -390,7 +390,7 @@ class TimeTestCase(unittest.TestCase):
info = time.get_clock_info('process_time') info = time.get_clock_info('process_time')
self.assertTrue(info.monotonic) self.assertTrue(info.monotonic)
self.assertFalse(info.adjusted) self.assertFalse(info.adjustable)
@unittest.skipUnless(hasattr(time, 'monotonic'), @unittest.skipUnless(hasattr(time, 'monotonic'),
'need time.monotonic') 'need time.monotonic')
...@@ -441,7 +441,7 @@ class TimeTestCase(unittest.TestCase): ...@@ -441,7 +441,7 @@ class TimeTestCase(unittest.TestCase):
# 0.0 < resolution <= 1.0 # 0.0 < resolution <= 1.0
self.assertGreater(info.resolution, 0.0) self.assertGreater(info.resolution, 0.0)
self.assertLessEqual(info.resolution, 1.0) self.assertLessEqual(info.resolution, 1.0)
self.assertIsInstance(info.adjusted, bool) self.assertIsInstance(info.adjustable, bool)
self.assertRaises(ValueError, time.get_clock_info, 'xxx') self.assertRaises(ValueError, time.get_clock_info, 'xxx')
......
...@@ -21,6 +21,8 @@ Core and Builtins ...@@ -21,6 +21,8 @@ Core and Builtins
Library Library
------- -------
- Rename adjusted attribute to adjustable in time.get_clock_info() result.
- Issue #3518: Remove references to non-existent BaseManager.from_address() - Issue #3518: Remove references to non-existent BaseManager.from_address()
method. method.
......
...@@ -96,7 +96,7 @@ floatclock(_Py_clock_info_t *info) ...@@ -96,7 +96,7 @@ floatclock(_Py_clock_info_t *info)
info->implementation = "clock()"; info->implementation = "clock()";
info->resolution = 1.0 / (double)CLOCKS_PER_SEC; info->resolution = 1.0 / (double)CLOCKS_PER_SEC;
info->monotonic = 1; info->monotonic = 1;
info->adjusted = 0; info->adjustable = 0;
} }
return PyFloat_FromDouble((double)value / CLOCKS_PER_SEC); return PyFloat_FromDouble((double)value / CLOCKS_PER_SEC);
} }
...@@ -132,7 +132,7 @@ win_perf_counter(_Py_clock_info_t *info, PyObject **result) ...@@ -132,7 +132,7 @@ win_perf_counter(_Py_clock_info_t *info, PyObject **result)
info->implementation = "QueryPerformanceCounter()"; info->implementation = "QueryPerformanceCounter()";
info->resolution = 1.0 / (double)cpu_frequency; info->resolution = 1.0 / (double)cpu_frequency;
info->monotonic = 1; info->monotonic = 1;
info->adjusted = 0; info->adjustable = 0;
} }
*result = PyFloat_FromDouble(diff / (double)cpu_frequency); *result = PyFloat_FromDouble(diff / (double)cpu_frequency);
return 0; return 0;
...@@ -882,7 +882,7 @@ pymonotonic(_Py_clock_info_t *info) ...@@ -882,7 +882,7 @@ pymonotonic(_Py_clock_info_t *info)
return NULL; return NULL;
} }
info->resolution = timeIncrement * 1e-7; info->resolution = timeIncrement * 1e-7;
info->adjusted = 0; info->adjustable = 0;
} }
return PyFloat_FromDouble(result); return PyFloat_FromDouble(result);
...@@ -903,7 +903,7 @@ pymonotonic(_Py_clock_info_t *info) ...@@ -903,7 +903,7 @@ pymonotonic(_Py_clock_info_t *info)
info->implementation = "mach_absolute_time()"; info->implementation = "mach_absolute_time()";
info->resolution = (double)timebase.numer / timebase.denom * 1e-9; info->resolution = (double)timebase.numer / timebase.denom * 1e-9;
info->monotonic = 1; info->monotonic = 1;
info->adjusted = 0; info->adjustable = 0;
} }
return PyFloat_FromDouble(secs); return PyFloat_FromDouble(secs);
...@@ -926,13 +926,7 @@ pymonotonic(_Py_clock_info_t *info) ...@@ -926,13 +926,7 @@ pymonotonic(_Py_clock_info_t *info)
struct timespec res; struct timespec res;
info->monotonic = 1; info->monotonic = 1;
info->implementation = function; info->implementation = function;
#if (defined(linux) || defined(__linux) || defined(__linux__)) \ info->adjustable = 0;
&& !defined(CLOCK_HIGHRES)
/* CLOCK_MONOTONIC is adjusted on Linux */
info->adjusted = 1;
#else
info->adjusted = 0;
#endif
if (clock_getres(clk_id, &res) == 0) if (clock_getres(clk_id, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9; info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
else else
...@@ -1024,7 +1018,7 @@ py_process_time(_Py_clock_info_t *info) ...@@ -1024,7 +1018,7 @@ py_process_time(_Py_clock_info_t *info)
info->implementation = "GetProcessTimes()"; info->implementation = "GetProcessTimes()";
info->resolution = 1e-7; info->resolution = 1e-7;
info->monotonic = 1; info->monotonic = 1;
info->adjusted = 0; info->adjustable = 0;
} }
return PyFloat_FromDouble(total * 1e-7); return PyFloat_FromDouble(total * 1e-7);
#else #else
...@@ -1053,7 +1047,7 @@ py_process_time(_Py_clock_info_t *info) ...@@ -1053,7 +1047,7 @@ py_process_time(_Py_clock_info_t *info)
struct timespec res; struct timespec res;
info->implementation = function; info->implementation = function;
info->monotonic = 1; info->monotonic = 1;
info->adjusted = 0; info->adjustable = 0;
if (clock_getres(clk_id, &res) == 0) if (clock_getres(clk_id, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9; info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
else else
...@@ -1071,7 +1065,7 @@ py_process_time(_Py_clock_info_t *info) ...@@ -1071,7 +1065,7 @@ py_process_time(_Py_clock_info_t *info)
if (info) { if (info) {
info->implementation = "getrusage(RUSAGE_SELF)"; info->implementation = "getrusage(RUSAGE_SELF)";
info->monotonic = 1; info->monotonic = 1;
info->adjusted = 0; info->adjustable = 0;
info->resolution = 1e-6; info->resolution = 1e-6;
} }
return PyFloat_FromDouble(total); return PyFloat_FromDouble(total);
...@@ -1100,7 +1094,7 @@ py_process_time(_Py_clock_info_t *info) ...@@ -1100,7 +1094,7 @@ py_process_time(_Py_clock_info_t *info)
if (info) { if (info) {
info->implementation = "times()"; info->implementation = "times()";
info->monotonic = 1; info->monotonic = 1;
info->adjusted = 0; info->adjustable = 0;
info->resolution = 1.0 / ticks_per_second; info->resolution = 1.0 / ticks_per_second;
} }
return PyFloat_FromDouble(total); return PyFloat_FromDouble(total);
...@@ -1137,12 +1131,12 @@ time_get_clock_info(PyObject *self, PyObject *args) ...@@ -1137,12 +1131,12 @@ time_get_clock_info(PyObject *self, PyObject *args)
#ifdef Py_DEBUG #ifdef Py_DEBUG
info.implementation = NULL; info.implementation = NULL;
info.monotonic = -1; info.monotonic = -1;
info.adjusted = -1; info.adjustable = -1;
info.resolution = -1.0; info.resolution = -1.0;
#else #else
info.implementation = ""; info.implementation = "";
info.monotonic = 0; info.monotonic = 0;
info.adjusted = 0; info.adjustable = 0;
info.resolution = 1.0; info.resolution = 1.0;
#endif #endif
...@@ -1188,11 +1182,11 @@ time_get_clock_info(PyObject *self, PyObject *args) ...@@ -1188,11 +1182,11 @@ time_get_clock_info(PyObject *self, PyObject *args)
goto error; goto error;
Py_CLEAR(obj); Py_CLEAR(obj);
assert(info.adjusted != -1); assert(info.adjustable != -1);
obj = PyBool_FromLong(info.adjusted); obj = PyBool_FromLong(info.adjustable);
if (obj == NULL) if (obj == NULL)
goto error; goto error;
if (PyDict_SetItemString(dict, "adjusted", obj) == -1) if (PyDict_SetItemString(dict, "adjustable", obj) == -1)
goto error; goto error;
Py_CLEAR(obj); Py_CLEAR(obj);
...@@ -1471,7 +1465,7 @@ floattime(_Py_clock_info_t *info) ...@@ -1471,7 +1465,7 @@ floattime(_Py_clock_info_t *info)
struct timespec res; struct timespec res;
info->implementation = "clock_gettime(CLOCK_REALTIME)"; info->implementation = "clock_gettime(CLOCK_REALTIME)";
info->monotonic = 0; info->monotonic = 0;
info->adjusted = 1; info->adjustable = 1;
if (clock_getres(CLOCK_REALTIME, &res) == 0) if (clock_getres(CLOCK_REALTIME, &res) == 0)
info->resolution = res.tv_sec + res.tv_nsec * 1e-9; info->resolution = res.tv_sec + res.tv_nsec * 1e-9;
else else
......
...@@ -44,10 +44,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info) ...@@ -44,10 +44,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
(void) GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement, (void) GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement,
&isTimeAdjustmentDisabled); &isTimeAdjustmentDisabled);
info->resolution = timeIncrement * 1e-7; info->resolution = timeIncrement * 1e-7;
if (isTimeAdjustmentDisabled) info->adjustable = 1;
info->adjusted = 0;
else
info->adjusted = 1;
} }
#else #else
/* There are three ways to get the time: /* There are three ways to get the time:
...@@ -71,7 +68,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info) ...@@ -71,7 +68,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
info->implementation = "gettimeofday()"; info->implementation = "gettimeofday()";
info->resolution = 1e-6; info->resolution = 1e-6;
info->monotonic = 0; info->monotonic = 0;
info->adjusted = 1; info->adjustable = 1;
} }
return; return;
} }
...@@ -87,7 +84,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info) ...@@ -87,7 +84,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
info->implementation = "ftime()"; info->implementation = "ftime()";
info->resolution = 1e-3; info->resolution = 1e-3;
info->monotonic = 0; info->monotonic = 0;
info->adjusted = 1; info->adjustable = 1;
} }
} }
#else /* !HAVE_FTIME */ #else /* !HAVE_FTIME */
...@@ -97,7 +94,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info) ...@@ -97,7 +94,7 @@ pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info)
info->implementation = "time()"; info->implementation = "time()";
info->resolution = 1.0; info->resolution = 1.0;
info->monotonic = 0; info->monotonic = 0;
info->adjusted = 1; info->adjustable = 1;
} }
#endif /* !HAVE_FTIME */ #endif /* !HAVE_FTIME */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment