diff --git a/Modules/timemodule.c b/Modules/timemodule.c --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -915,23 +915,28 @@ floatsleep(double secs) #if defined(HAVE_SELECT) && !defined(__EMX__) struct timeval t; double frac; + int err; + frac = fmod(secs, 1.0); secs = floor(secs); t.tv_sec = (long)secs; t.tv_usec = (long)(frac*1000000.0); 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) { + if (PyErr_CheckSignals()) + return -1; #ifdef EINTR - if (errno != EINTR) { + if (errno != EINTR) #else - if (1) { + if (1) #endif - Py_BLOCK_THREADS + { PyErr_SetFromErrno(PyExc_IOError); return -1; } } - Py_END_ALLOW_THREADS #elif defined(__WATCOMC__) && !defined(__QNX__) /* XXX Can't interrupt this sleep */ Py_BEGIN_ALLOW_THREADS @@ -941,6 +946,7 @@ floatsleep(double secs) { double millisecs = secs * 1000.0; unsigned long ul_millis; + int interrupted; if (millisecs > (double)ULONG_MAX) { PyErr_SetString(PyExc_OverflowError, @@ -953,8 +959,10 @@ floatsleep(double secs) */ ul_millis = (unsigned long)millisecs; if (ul_millis == 0 || - main_thread != PyThread_get_thread_ident()) - Sleep(ul_millis); + main_thread != PyThread_get_thread_ident()) { + Sleep(0); + interrupted = 0; + } else { DWORD rc; ResetEvent(hInterruptEvent); @@ -964,13 +972,17 @@ floatsleep(double secs) * handler called. */ Sleep(1); - Py_BLOCK_THREADS - errno = EINTR; - PyErr_SetFromErrno(PyExc_IOError); - return -1; + interrupted = 1; } } Py_END_ALLOW_THREADS + if (interrupted) { + if (PyErr_CheckSignals()) + return -1; + errno = EINTR; + PyErr_SetFromErrno(PyExc_IOError); + return -1; + } } #elif defined(PYOS_OS2) /* This Sleep *IS* Interruptable by Exceptions */