[Python-checkins] cpython: Issue #12462: time.sleep() now calls immediatly the (Python) signal handler if

victor.stinner python-checkins at python.org
Fri Jul 1 14:19:30 CEST 2011


http://hg.python.org/cpython/rev/583be15e22ca
changeset:   71111:583be15e22ca
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Fri Jul 01 13:50:09 2011 +0200
summary:
  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.

files:
  Misc/NEWS            |   4 ++++
  Modules/timemodule.c |  17 +++++++++++------
  2 files changed, 15 insertions(+), 6 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -200,6 +200,10 @@
 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.
 
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -915,23 +915,28 @@
 #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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list