Merged revisions 78523 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78523 | gregory.p.smith | 2010-02-28 16:05:08 -0800 (Sun, 28 Feb 2010) | 3 lines

  Issue #1068268: The subprocess module now handles EINTR in internal
  os.waitpid and os.read system calls where appropriate.
........
This commit is contained in:
Gregory P. Smith 2010-03-01 00:35:34 +00:00
parent 9922a9a9cf
commit ca57499b72
3 changed files with 38 additions and 4 deletions

View file

@ -459,6 +459,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.
@ -1114,13 +1124,14 @@ 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
# 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:
@ -1156,7 +1167,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