summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2017-10-18 09:09:57 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-10-18 09:09:57 (GMT)
commitbe4e9cc769aac3cb46670c049b9f21e412be53d1 (patch)
treececaf808562d39817ecaa52ab0056f6229fb0624
parent95602b368b87da3702a0f340ded2a23e823bb104 (diff)
downloadcpython-be4e9cc769aac3cb46670c049b9f21e412be53d1.zip
cpython-be4e9cc769aac3cb46670c049b9f21e412be53d1.tar.gz
cpython-be4e9cc769aac3cb46670c049b9f21e412be53d1.tar.bz2
[3.6] bpo-31806: Use _PyTime_ROUND_TIMEOUT for the timeout argument parsing in more functions (GH-4026) (#4032)
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)
-rw-r--r--Misc/NEWS.d/next/Library/2017-10-17-23-27-03.bpo-31806.TzphdL.rst4
-rw-r--r--Modules/_threadmodule.c4
-rw-r--r--Modules/socketmodule.c6
-rw-r--r--Modules/timemodule.c2
4 files changed, 10 insertions, 6 deletions
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
index 0000000..941e77d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-10-17-23-27-03.bpo-31806.TzphdL.rst
@@ -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.
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 0219559..47e84b9 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -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");
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index a351faa..da84291 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -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) {
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 0abe569..dba3d04 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -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,