]> granicus.if.org Git - python/commitdiff
[3.6] bpo-31806: Use _PyTime_ROUND_TIMEOUT for the timeout argument parsing in more...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 18 Oct 2017 09:09:57 +0000 (02:09 -0700)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 18 Oct 2017 09:09:57 +0000 (12:09 +0300)
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)

Misc/NEWS.d/next/Library/2017-10-17-23-27-03.bpo-31806.TzphdL.rst [new file with mode: 0644]
Modules/_threadmodule.c
Modules/socketmodule.c
Modules/timemodule.c

diff --git a/Misc/NEWS.d/next/Library/2017-10-17-23-27-03.bpo-31806.TzphdL.rst b/Misc/NEWS.d/next/Library/2017-10-17-23-27-03.bpo-31806.TzphdL.rst
new file mode 100644 (file)
index 0000000..941e77d
--- /dev/null
@@ -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.
index 02195596093771f24e989c014f62f65468fae9d4..47e84b9e916d9928b28c89fd81d9b327d72cee68 100644 (file)
@@ -111,7 +111,7 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
 
     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 ) {
@@ -129,7 +129,7 @@ lock_acquire_parse_args(PyObject *args, PyObject *kwds,
     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");
index a351faa7f9fabfffd30b1f0116d8198c68bbbb93..da84291edcf908db0c5d75d70c697026b297fe43 100644 (file)
@@ -2454,7 +2454,7 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
     }
 
     if (_PyTime_FromSecondsObject(timeout,
-                                  timeout_obj, _PyTime_ROUND_CEILING) < 0)
+                                  timeout_obj, _PyTime_ROUND_TIMEOUT) < 0)
         return -1;
 
     if (*timeout < 0) {
@@ -2463,10 +2463,10 @@ socket_parse_timeout(_PyTime_t *timeout, PyObject *timeout_obj)
     }
 
 #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) {
index 0abe569f137c0d828af77d27bdf2ec8a8b003e97..dba3d0452acbb0c92878ad6afdb8601da0bb85a9 100644 (file)
@@ -225,7 +225,7 @@ static PyObject *
 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,