bpo-36895: remove time.clock() as per removal notice. (GH-13270)
`time.clock()` was deprecated in 3.3, and marked for removal removal in 3.8; this thus remove it from the time module.
This commit is contained in:
parent
5d23e282af
commit
e2500610c6
|
@ -155,7 +155,7 @@ Functions
|
||||||
|
|
||||||
.. availability:: Windows, Unix. Not available on VxWorks.
|
.. availability:: Windows, Unix. Not available on VxWorks.
|
||||||
|
|
||||||
.. deprecated:: 3.3
|
.. deprecated-removed:: 3.3 3.8
|
||||||
The behaviour of this function depends on the platform: use
|
The behaviour of this function depends on the platform: use
|
||||||
:func:`perf_counter` or :func:`process_time` instead, depending on your
|
:func:`perf_counter` or :func:`process_time` instead, depending on your
|
||||||
requirements, to have a well defined behaviour.
|
requirements, to have a well defined behaviour.
|
||||||
|
|
|
@ -88,17 +88,6 @@ class TimeTestCase(unittest.TestCase):
|
||||||
check_ns(time.clock_gettime(time.CLOCK_REALTIME),
|
check_ns(time.clock_gettime(time.CLOCK_REALTIME),
|
||||||
time.clock_gettime_ns(time.CLOCK_REALTIME))
|
time.clock_gettime_ns(time.CLOCK_REALTIME))
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(time, 'clock'),
|
|
||||||
'need time.clock()')
|
|
||||||
def test_clock(self):
|
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
time.clock()
|
|
||||||
|
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
info = time.get_clock_info('clock')
|
|
||||||
self.assertTrue(info.monotonic)
|
|
||||||
self.assertFalse(info.adjustable)
|
|
||||||
|
|
||||||
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
|
@unittest.skipUnless(hasattr(time, 'clock_gettime'),
|
||||||
'need time.clock_gettime()')
|
'need time.clock_gettime()')
|
||||||
def test_clock_realtime(self):
|
def test_clock_realtime(self):
|
||||||
|
@ -553,15 +542,9 @@ class TimeTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_clock_info(self):
|
def test_get_clock_info(self):
|
||||||
clocks = ['monotonic', 'perf_counter', 'process_time', 'time']
|
clocks = ['monotonic', 'perf_counter', 'process_time', 'time']
|
||||||
if hasattr(time, 'clock'):
|
|
||||||
clocks.append('clock')
|
|
||||||
|
|
||||||
for name in clocks:
|
for name in clocks:
|
||||||
if name == 'clock':
|
info = time.get_clock_info(name)
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
info = time.get_clock_info('clock')
|
|
||||||
else:
|
|
||||||
info = time.get_clock_info(name)
|
|
||||||
|
|
||||||
#self.assertIsInstance(info, dict)
|
#self.assertIsInstance(info, dict)
|
||||||
self.assertIsInstance(info.implementation, str)
|
self.assertIsInstance(info.implementation, str)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
The function ``time.clock()`` was deprecated in 3.3 in favor of
|
||||||
|
``time.perf_counter()`` and marked for removal in 3.8, it has removed.
|
|
@ -145,44 +145,6 @@ perf_counter(_Py_clock_info_t *info)
|
||||||
return _PyFloat_FromPyTime(t);
|
return _PyFloat_FromPyTime(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (defined(MS_WINDOWS) || defined(HAVE_CLOCK)) && !defined(__VXWORKS__)
|
|
||||||
#define PYCLOCK
|
|
||||||
static PyObject*
|
|
||||||
pyclock(_Py_clock_info_t *info)
|
|
||||||
{
|
|
||||||
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
|
||||||
"time.clock has been deprecated in Python 3.3 and will "
|
|
||||||
"be removed from Python 3.8: "
|
|
||||||
"use time.perf_counter or time.process_time "
|
|
||||||
"instead", 1) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
|
||||||
return perf_counter(info);
|
|
||||||
#else
|
|
||||||
_PyTime_t t;
|
|
||||||
if (_PyTime_GetClockWithInfo(&t, info) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return _PyFloat_FromPyTime(t);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
time_clock(PyObject *self, PyObject *unused)
|
|
||||||
{
|
|
||||||
return pyclock(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
PyDoc_STRVAR(clock_doc,
|
|
||||||
"clock() -> floating point number\n\
|
|
||||||
\n\
|
|
||||||
Return the CPU time or real time since the start of the process or since\n\
|
|
||||||
the first call to clock(). This has as much precision as the system\n\
|
|
||||||
records.");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_CLOCK_GETTIME
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
static PyObject *
|
static PyObject *
|
||||||
time_clock_gettime(PyObject *self, PyObject *args)
|
time_clock_gettime(PyObject *self, PyObject *args)
|
||||||
|
@ -1477,15 +1439,6 @@ time_get_clock_info(PyObject *self, PyObject *args)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef PYCLOCK
|
|
||||||
else if (strcmp(name, "clock") == 0) {
|
|
||||||
obj = pyclock(&info);
|
|
||||||
if (obj == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
Py_DECREF(obj);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
else if (strcmp(name, "monotonic") == 0) {
|
else if (strcmp(name, "monotonic") == 0) {
|
||||||
if (_PyTime_GetMonotonicClockWithInfo(&t, &info) < 0) {
|
if (_PyTime_GetMonotonicClockWithInfo(&t, &info) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1700,9 +1653,6 @@ init_timezone(PyObject *m)
|
||||||
static PyMethodDef time_methods[] = {
|
static PyMethodDef time_methods[] = {
|
||||||
{"time", time_time, METH_NOARGS, time_doc},
|
{"time", time_time, METH_NOARGS, time_doc},
|
||||||
{"time_ns", time_time_ns, METH_NOARGS, time_ns_doc},
|
{"time_ns", time_time_ns, METH_NOARGS, time_ns_doc},
|
||||||
#ifdef PYCLOCK
|
|
||||||
{"clock", time_clock, METH_NOARGS, clock_doc},
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_CLOCK_GETTIME
|
#ifdef HAVE_CLOCK_GETTIME
|
||||||
{"clock_gettime", time_clock_gettime, METH_VARARGS, clock_gettime_doc},
|
{"clock_gettime", time_clock_gettime, METH_VARARGS, clock_gettime_doc},
|
||||||
{"clock_gettime_ns",time_clock_gettime_ns, METH_VARARGS, clock_gettime_ns_doc},
|
{"clock_gettime_ns",time_clock_gettime_ns, METH_VARARGS, clock_gettime_ns_doc},
|
||||||
|
|
Loading…
Reference in New Issue