Commit 0ac39c44 authored by Victor Stinner's avatar Victor Stinner

Issue #12462: time.sleep() now calls immediatly the (Python) signal handler if

it is interrupted by a signal, instead of having to wait until the next
instruction.

Patch reviewed by Antoine Pitrou.
parent 5db762da
...@@ -200,6 +200,10 @@ Core and Builtins ...@@ -200,6 +200,10 @@ Core and Builtins
Library Library
------- -------
- Issue #12462: time.sleep() now calls immediatly the (Python) signal handler
if it is interrupted by a signal, instead of having to wait until the next
instruction.
- Issue #12442: new shutil.disk_usage function, providing total, used and free - Issue #12442: new shutil.disk_usage function, providing total, used and free
disk space statistics. disk space statistics.
......
...@@ -915,23 +915,28 @@ floatsleep(double secs) ...@@ -915,23 +915,28 @@ floatsleep(double secs)
#if defined(HAVE_SELECT) && !defined(__EMX__) #if defined(HAVE_SELECT) && !defined(__EMX__)
struct timeval t; struct timeval t;
double frac; double frac;
int err;
frac = fmod(secs, 1.0); frac = fmod(secs, 1.0);
secs = floor(secs); secs = floor(secs);
t.tv_sec = (long)secs; t.tv_sec = (long)secs;
t.tv_usec = (long)(frac*1000000.0); t.tv_usec = (long)(frac*1000000.0);
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) { err = select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
Py_END_ALLOW_THREADS
if (err != 0) {
#ifdef EINTR #ifdef EINTR
if (errno != EINTR) { if (errno == EINTR) {
#else if (PyErr_CheckSignals())
if (1) { return -1;
}
else
#endif #endif
Py_BLOCK_THREADS {
PyErr_SetFromErrno(PyExc_IOError); PyErr_SetFromErrno(PyExc_IOError);
return -1; return -1;
} }
} }
Py_END_ALLOW_THREADS
#elif defined(__WATCOMC__) && !defined(__QNX__) #elif defined(__WATCOMC__) && !defined(__QNX__)
/* XXX Can't interrupt this sleep */ /* XXX Can't interrupt this sleep */
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment