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.
This commit is contained in:
Victor Stinner 2015-03-20 01:42:20 +01:00
parent 4fa99cdb4c
commit 9a8089b32a
5 changed files with 27 additions and 15 deletions

View file

@ -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);