Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
30d79471
Commit
30d79471
authored
Apr 03, 2012
by
Victor Stinner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose clock_settime() as time.clock_settime()
parent
1470f35b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
0 deletions
+48
-0
Doc/library/time.rst
Doc/library/time.rst
+7
-0
Lib/test/test_time.py
Lib/test/test_time.py
+11
-0
Modules/timemodule.c
Modules/timemodule.c
+30
-0
No files found.
Doc/library/time.rst
View file @
30d79471
...
...
@@ -151,6 +151,13 @@ The module defines the following functions and data items:
.. versionadded:: 3.3
.. function:: clock_settime(clk_id, time)
Set the time of the specified clock *clk_id*.
.. versionadded:: 3.3
.. data:: CLOCK_REALTIME
System-wide real-time clock. Setting this clock requires appropriate
...
...
Lib/test/test_time.py
View file @
30d79471
...
...
@@ -47,6 +47,17 @@ class TimeTestCase(unittest.TestCase):
self
.
assertGreater
(
res
,
0.0
)
self
.
assertLessEqual
(
res
,
1.0
)
@
unittest
.
skipUnless
(
hasattr
(
time
,
'clock_settime'
),
'need time.clock_settime()'
)
def
test_clock_settime
(
self
):
t
=
time
.
clock_gettime
(
time
.
CLOCK_REALTIME
)
try
:
time
.
clock_settime
(
time
.
CLOCK_REALTIME
,
t
)
except
PermissionError
:
pass
self
.
assertRaises
(
OSError
,
time
.
clock_settime
,
time
.
CLOCK_MONOTONIC
,
0
)
def
test_conversions
(
self
):
self
.
assertEqual
(
time
.
ctime
(
self
.
t
),
time
.
asctime
(
time
.
localtime
(
self
.
t
)))
...
...
Modules/timemodule.c
View file @
30d79471
...
...
@@ -158,6 +158,33 @@ PyDoc_STRVAR(clock_gettime_doc,
"clock_gettime(clk_id) -> floating point number
\n
\
\n
\
Return the time of the specified clock clk_id."
);
static
PyObject
*
time_clock_settime
(
PyObject
*
self
,
PyObject
*
args
)
{
clockid_t
clk_id
;
PyObject
*
obj
;
struct
timespec
tp
;
int
ret
;
if
(
!
PyArg_ParseTuple
(
args
,
"iO:clock_settime"
,
&
clk_id
,
&
obj
))
return
NULL
;
if
(
_PyTime_ObjectToTimespec
(
obj
,
&
tp
.
tv_sec
,
&
tp
.
tv_nsec
)
==
-
1
)
return
NULL
;
ret
=
clock_settime
((
clockid_t
)
clk_id
,
&
tp
);
if
(
ret
!=
0
)
{
PyErr_SetFromErrno
(
PyExc_IOError
);
return
NULL
;
}
Py_RETURN_NONE
;
}
PyDoc_STRVAR
(
clock_settime_doc
,
"clock_settime(clk_id, time)
\n
\
\n
\
Set the time of the specified clock clk_id."
);
#endif
#ifdef HAVE_CLOCK_GETRES
...
...
@@ -983,6 +1010,9 @@ static PyMethodDef time_methods[] = {
#ifdef HAVE_CLOCK_GETTIME
{
"clock_gettime"
,
time_clock_gettime
,
METH_VARARGS
,
clock_gettime_doc
},
#endif
#ifdef HAVE_CLOCK_GETTIME
{
"clock_settime"
,
time_clock_settime
,
METH_VARARGS
,
clock_settime_doc
},
#endif
#ifdef HAVE_CLOCK_GETRES
{
"clock_getres"
,
time_clock_getres
,
METH_VARARGS
,
clock_getres_doc
},
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment