]> granicus.if.org Git - python/commitdiff
Issue #17018: Make Process.join() retry if os.waitpid() fails with EINTR.
authorRichard Oudkerk <shibturn@gmail.com>
Tue, 26 Feb 2013 12:37:07 +0000 (12:37 +0000)
committerRichard Oudkerk <shibturn@gmail.com>
Tue, 26 Feb 2013 12:37:07 +0000 (12:37 +0000)
Lib/multiprocessing/forking.py
Lib/test/test_multiprocessing.py
Misc/NEWS

index 55980ffdcad963735bdfcae77c65342bf2f87a90..1597ae8f2e3d36e4303c67483d38f651147380b5 100644 (file)
@@ -35,6 +35,7 @@
 import os
 import sys
 import signal
+import errno
 
 from multiprocessing import util, process
 
@@ -129,12 +130,17 @@ if sys.platform != 'win32':
 
         def poll(self, flag=os.WNOHANG):
             if self.returncode is None:
-                try:
-                    pid, sts = os.waitpid(self.pid, flag)
-                except os.error:
-                    # Child process not yet created. See #1731717
-                    # e.errno == errno.ECHILD == 10
-                    return None
+                while True:
+                    try:
+                        pid, sts = os.waitpid(self.pid, flag)
+                    except os.error as e:
+                        if e.errno == errno.EINTR:
+                            continue
+                        # Child process not yet created. See #1731717
+                        # e.errno == errno.ECHILD == 10
+                        return None
+                    else:
+                        break
                 if pid == self.pid:
                     if os.WIFSIGNALED(sts):
                         self.returncode = -os.WTERMSIG(sts)
index f140aca63f179e5ede9b93369d85b576c25bff43..9b3f0a96473c6a6bc23eb9a0b8401e5d7be6cc01 100644 (file)
@@ -2104,6 +2104,38 @@ class _TestLogging(BaseTestCase):
 #         logger.warn('foo')
 #         assert self.__handled
 
+#
+# Check that Process.join() retries if os.waitpid() fails with EINTR
+#
+
+class _TestPollEintr(BaseTestCase):
+
+    ALLOWED_TYPES = ('processes',)
+
+    @classmethod
+    def _killer(cls, pid):
+        time.sleep(0.5)
+        os.kill(pid, signal.SIGUSR1)
+
+    @unittest.skipUnless(hasattr(signal, 'SIGUSR1'), 'requires SIGUSR1')
+    def test_poll_eintr(self):
+        got_signal = [False]
+        def record(*args):
+            got_signal[0] = True
+        pid = os.getpid()
+        oldhandler = signal.signal(signal.SIGUSR1, record)
+        try:
+            killer = self.Process(target=self._killer, args=(pid,))
+            killer.start()
+            p = self.Process(target=time.sleep, args=(1,))
+            p.start()
+            p.join()
+            self.assertTrue(got_signal[0])
+            self.assertEqual(p.exitcode, 0)
+            killer.join()
+        finally:
+            signal.signal(signal.SIGUSR1, oldhandler)
+
 #
 # Test to verify handle verification, see issue 3321
 #
index a89a9a4b9bac6978bbf65e2fb60979b890670235..12526b2278098f7e998797d1ef4ffa607c01956b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -211,6 +211,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #17018: Make Process.join() retry if os.waitpid() fails with EINTR.
+
 - Issue #14720: sqlite3: Convert datetime microseconds correctly.
   Patch by Lowe Thiderman.