Fix timeout rounding in time.sleep(), threading.Lock.acquire() and
socket.socket.settimeout() to round correctly negative timeouts between -1.0 and
0.0. The functions now block waiting for events as expected. Previously, the
call was incorrectly non-blocking.
(cherry picked from commit
59af94fa61bf90adbe624508e909b5d6ef6e8464)
--- /dev/null
+Fix timeout rounding in time.sleep(), threading.Lock.acquire() and
+socket.socket.settimeout() to round correctly negative timeouts between -1.0 and
+0.0. The functions now block waiting for events as expected. Previously, the
+call was incorrectly non-blocking. Patch by Pablo Galindo.
if (timeout_obj
&& _PyTime_FromSecondsObject(timeout,
- timeout_obj, _PyTime_ROUND_CEILING) < 0)
+ timeout_obj, _PyTime_ROUND_TIMEOUT) < 0)
return -1;
if (!blocking && *timeout != unset_timeout ) {
else if (*timeout != unset_timeout) {
_PyTime_t microseconds;
- microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_CEILING);
+ microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_TIMEOUT);
if (microseconds >= PY_TIMEOUT_MAX) {
PyErr_SetString(PyExc_OverflowError,
"timeout value is too large");
}
if (_PyTime_FromSecondsObject(timeout,
- timeout_obj, _PyTime_ROUND_CEILING) < 0)
+ timeout_obj, _PyTime_ROUND_TIMEOUT) < 0)
return -1;
if (*timeout < 0) {
}
#ifdef MS_WINDOWS
- overflow |= (_PyTime_AsTimeval(*timeout, &tv, _PyTime_ROUND_CEILING) < 0);
+ overflow |= (_PyTime_AsTimeval(*timeout, &tv, _PyTime_ROUND_TIMEOUT) < 0);
#endif
#ifndef HAVE_POLL
- ms = _PyTime_AsMilliseconds(*timeout, _PyTime_ROUND_CEILING);
+ ms = _PyTime_AsMilliseconds(*timeout, _PyTime_ROUND_TIMEOUT);
overflow |= (ms > INT_MAX);
#endif
if (overflow) {
time_sleep(PyObject *self, PyObject *obj)
{
_PyTime_t secs;
- if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_CEILING))
+ if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_TIMEOUT))
return NULL;
if (secs < 0) {
PyErr_SetString(PyExc_ValueError,