]> granicus.if.org Git - python/commitdiff
Issue #12462: time.sleep() now calls immediatly the (Python) signal handler if
authorVictor Stinner <victor.stinner@haypocalc.com>
Fri, 1 Jul 2011 11:50:09 +0000 (13:50 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Fri, 1 Jul 2011 11:50:09 +0000 (13:50 +0200)
it is interrupted by a signal, instead of having to wait until the next
instruction.

Patch reviewed by Antoine Pitrou.

Misc/NEWS
Modules/timemodule.c

index a0ab6a15f57c915f31b1bfed708a7b5b3ce693d7..6e0882b962df757e84e9fe04d16f7b57dd10aa8e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -200,6 +200,10 @@ Core and Builtins
 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
   disk space statistics.
 
index 2b86bcb4914010eea8152dc3619a0f34a0cfee62..75aa8b61b8caefa549229cf95c9b87f9fda105d5 100644 (file)
@@ -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 != 0) {
 #ifdef EINTR
-        if (errno != EINTR) {
-#else
-        if (1) {
+        if (errno == EINTR) {
+            if (PyErr_CheckSignals())
+                return -1;
+        }
+        else
 #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