summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Oudkerk <shibturn@gmail.com>2013-02-26 12:39:57 (GMT)
committerRichard Oudkerk <shibturn@gmail.com>2013-02-26 12:39:57 (GMT)
commit7aaa1ef8580660eb6ba94a48ffaf76acbc75a8a6 (patch)
tree8a83c0c8bc3dc06f1458075af2aa1795409d95ff
parent8fd366978d2020b28442831bd28df85824856e30 (diff)
downloadcpython-7aaa1ef8580660eb6ba94a48ffaf76acbc75a8a6.zip
cpython-7aaa1ef8580660eb6ba94a48ffaf76acbc75a8a6.tar.gz
cpython-7aaa1ef8580660eb6ba94a48ffaf76acbc75a8a6.tar.bz2
Issue #17018: Make Process.join() retry if os.waitpid() fails with EINTR.
-rw-r--r--Lib/multiprocessing/forking.py18
-rw-r--r--Lib/test/test_multiprocessing.py32
-rw-r--r--Misc/NEWS2
3 files changed, 46 insertions, 6 deletions
diff --git a/Lib/multiprocessing/forking.py b/Lib/multiprocessing/forking.py
index bc8ac44..8dc4b00 100644
--- a/Lib/multiprocessing/forking.py
+++ b/Lib/multiprocessing/forking.py
@@ -35,6 +35,7 @@
import os
import sys
import signal
+import errno
from multiprocessing import util, process
@@ -128,12 +129,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)
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
index fa4865b..05fba7f 100644
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -2168,6 +2168,38 @@ class _TestLogging(BaseTestCase):
# 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
#
diff --git a/Misc/NEWS b/Misc/NEWS
index eb30662..3cd2a81 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -230,6 +230,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.