File python-2.6.2-eintr.patch of Package python-base
Index: Lib/subprocess.py
===================================================================
--- Lib/subprocess.py.orig
+++ Lib/subprocess.py
@@ -433,6 +433,16 @@ PIPE = -1
STDOUT = -2
+def _eintr_retry_call(func, *args):
+ while True:
+ try:
+ return func(*args)
+ except OSError, e:
+ if e.errno == errno.EINTR:
+ continue
+ raise
+
+
def call(*popenargs, **kwargs):
"""Run command with arguments. Wait for command to complete, then
return the returncode attribute.
@@ -1081,10 +1091,10 @@ class Popen(object):
os.close(errwrite)
# Wait for exec to fail or succeed; possibly raising exception
- data = os.read(errpipe_read, 1048576) # Exceptions limited to 1 MB
+ data = _eintr_retry_call(os.read, errpipe_read, 1048576) # Exceptions limited to 1 MB
os.close(errpipe_read)
if data != "":
- os.waitpid(self.pid, 0)
+ _eintr_retry_call(os.waitpid, self.pid, 0)
child_exception = pickle.loads(data)
for fd in (p2cwrite, c2pread, errread):
if fd is not None:
@@ -1120,7 +1130,7 @@ class Popen(object):
"""Wait for child process to terminate. Returns returncode
attribute."""
if self.returncode is None:
- pid, sts = os.waitpid(self.pid, 0)
+ pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
self._handle_exitstatus(sts)
return self.returncode
Index: Lib/test/test_subprocess.py
===================================================================
--- Lib/test/test_subprocess.py.orig
+++ Lib/test/test_subprocess.py
@@ -4,6 +4,7 @@ import subprocess
import sys
import signal
import os
+import errno
import tempfile
import time
import re
@@ -732,8 +733,25 @@ class ProcessTestCase(unittest.TestCase)
p.terminate()
self.assertNotEqual(p.wait(), 0)
+class HelperFunctionTests(unittest.TestCase):
+ def test_eintr_retry_call(self):
+ record_calls = []
+ def fake_os_func(*args):
+ record_calls.append(args)
+ if len(record_calls) == 2:
+ raise OSError(errno.EINTR, "fake interrupted system call")
+ return tuple(reversed(args))
+
+ self.assertEqual((999, 256),
+ subprocess._eintr_retry_call(fake_os_func, 256, 999))
+ self.assertEqual([(256, 999)], record_calls)
+ # This time there will be an EINTR so it will loop once.
+ self.assertEqual((666,),
+ subprocess._eintr_retry_call(fake_os_func, 666))
+ self.assertEqual([(256, 999), (666,), (666,)], record_calls)
+
def test_main():
- test_support.run_unittest(ProcessTestCase)
+ test_support.run_unittest(ProcessTestCase, HelperFunctionTests)
if hasattr(test_support, "reap_children"):
test_support.reap_children()