From cce211f88c3d23bbd37f5769e3addd9b6b9fa96e Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Mon, 1 Mar 2010 00:05:08 +0000 Subject: Issue #1068268: The subprocess module now handles EINTR in internal os.waitpid and os.read system calls where appropriate. --- Lib/subprocess.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Lib/subprocess.py') diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 2a4c1567aa..ba5ce01575 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -476,6 +476,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. @@ -1173,13 +1183,14 @@ class Popen(object): os.close(errwrite) # Wait for exec to fail or succeed; possibly raising exception - data = os.read(errpipe_read, 1048576) # Exception limited to 1M + # Exception limited to 1M + data = _eintr_retry_call(os.read, errpipe_read, 1048576) finally: # be sure the FD is closed no matter what 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: @@ -1215,7 +1226,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 -- cgit v1.2.1