mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-31806: Use _PyTime_ROUND_TIMEOUT for the timeout argument parsing in more functions (#4026)
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.
This commit is contained in:
parent
ec12df1e6e
commit
59af94fa61
4 changed files with 10 additions and 6 deletions
|
@ -0,0 +1,4 @@
|
||||||
|
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.
|
|
@ -104,7 +104,7 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
|
||||||
|
|
||||||
if (timeout_obj
|
if (timeout_obj
|
||||||
&& _PyTime_FromSecondsObject(timeout,
|
&& _PyTime_FromSecondsObject(timeout,
|
||||||
timeout_obj, _PyTime_ROUND_CEILING) < 0)
|
timeout_obj, _PyTime_ROUND_TIMEOUT) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!blocking && *timeout != unset_timeout ) {
|
if (!blocking && *timeout != unset_timeout ) {
|
||||||
|
@ -122,7 +122,7 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
|
||||||
else if (*timeout != unset_timeout) {
|
else if (*timeout != unset_timeout) {
|
||||||
_PyTime_t microseconds;
|
_PyTime_t microseconds;
|
||||||
|
|
||||||
microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_CEILING);
|
microseconds = _PyTime_AsMicroseconds(*timeout, _PyTime_ROUND_TIMEOUT);
|
||||||
if (microseconds >= PY_TIMEOUT_MAX) {
|
if (microseconds >= PY_TIMEOUT_MAX) {
|
||||||
PyErr_SetString(PyExc_OverflowError,
|
PyErr_SetString(PyExc_OverflowError,
|
||||||
"timeout value is too large");
|
"timeout value is too large");
|
||||||
|
|
|
@ -2539,7 +2539,7 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_PyTime_FromSecondsObject(timeout,
|
if (_PyTime_FromSecondsObject(timeout,
|
||||||
timeout_obj, _PyTime_ROUND_CEILING) < 0)
|
timeout_obj, _PyTime_ROUND_TIMEOUT) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (*timeout < 0) {
|
if (*timeout < 0) {
|
||||||
|
@ -2548,10 +2548,10 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
overflow |= (_PyTime_AsTimeval(*timeout, &tv, _PyTime_ROUND_CEILING) < 0);
|
overflow |= (_PyTime_AsTimeval(*timeout, &tv, _PyTime_ROUND_TIMEOUT) < 0);
|
||||||
#endif
|
#endif
|
||||||
#ifndef HAVE_POLL
|
#ifndef HAVE_POLL
|
||||||
ms = _PyTime_AsMilliseconds(*timeout, _PyTime_ROUND_CEILING);
|
ms = _PyTime_AsMilliseconds(*timeout, _PyTime_ROUND_TIMEOUT);
|
||||||
overflow |= (ms > INT_MAX);
|
overflow |= (ms > INT_MAX);
|
||||||
#endif
|
#endif
|
||||||
if (overflow) {
|
if (overflow) {
|
||||||
|
|
|
@ -245,7 +245,7 @@ static PyObject *
|
||||||
time_sleep(PyObject *self, PyObject *obj)
|
time_sleep(PyObject *self, PyObject *obj)
|
||||||
{
|
{
|
||||||
_PyTime_t secs;
|
_PyTime_t secs;
|
||||||
if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_CEILING))
|
if (_PyTime_FromSecondsObject(&secs, obj, _PyTime_ROUND_TIMEOUT))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (secs < 0) {
|
if (secs < 0) {
|
||||||
PyErr_SetString(PyExc_ValueError,
|
PyErr_SetString(PyExc_ValueError,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue