summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-03-20 00:42:20 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-03-20 00:42:20 (GMT)
commit9a8089b32adee874caefbe2a96096998625c5a78 (patch)
treebf91050cbe41ad7811a975acc3bab8ed4ee97c02 /Modules
parent4fa99cdb4c5f53d6fa86ef223ae613cb1a8783f8 (diff)
downloadcpython-9a8089b32adee874caefbe2a96096998625c5a78.zip
cpython-9a8089b32adee874caefbe2a96096998625c5a78.tar.gz
cpython-9a8089b32adee874caefbe2a96096998625c5a78.tar.bz2
Issue #23646: Enhance precision of time.sleep() and socket timeout when
interrupted by a signal Add a new _PyTime_AddDouble() function and remove _PyTime_ADD_SECONDS() macro. The _PyTime_ADD_SECONDS only supported an integer number of seconds, the _PyTime_AddDouble() has subsecond resolution.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c2
-rw-r--r--Modules/timemodule.c4
2 files changed, 3 insertions, 3 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 057430b..480ee5a 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -687,7 +687,7 @@ internal_select(PySocketSockObject *s, int writing)
if (has_timeout) { \
_PyTime_monotonic(&now); \
deadline = now; \
- _PyTime_ADD_SECONDS(deadline, s->sock_timeout); \
+ _PyTime_AddDouble(&deadline, s->sock_timeout, _PyTime_ROUND_UP); \
} \
while (1) { \
errno = 0; \
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 179c33f..204626e 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -1399,14 +1399,14 @@ floatsleep(double secs)
#endif
_PyTime_monotonic(&deadline);
- _PyTime_ADD_SECONDS(deadline, secs);
+ _PyTime_AddDouble(&deadline, secs, _PyTime_ROUND_UP);
do {
#ifndef MS_WINDOWS
frac = fmod(secs, 1.0);
secs = floor(secs);
timeout.tv_sec = (long)secs;
- timeout.tv_usec = (long)(frac*1000000.0);
+ timeout.tv_usec = (long)(frac*1e6);
Py_BEGIN_ALLOW_THREADS
err = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout);