Commit 02ba73c0 authored by Ross Lagerwall's avatar Ross Lagerwall

Merge with 3.1

parents 4333affb 4f61b025
...@@ -345,6 +345,7 @@ import gc ...@@ -345,6 +345,7 @@ import gc
import signal import signal
import builtins import builtins
import warnings import warnings
import errno
# Exception classes used by this module. # Exception classes used by this module.
class CalledProcessError(Exception): class CalledProcessError(Exception):
...@@ -376,7 +377,6 @@ if mswindows: ...@@ -376,7 +377,6 @@ if mswindows:
else: else:
import select import select
_has_poll = hasattr(select, 'poll') _has_poll = hasattr(select, 'poll')
import errno
import fcntl import fcntl
import pickle import pickle
...@@ -785,7 +785,11 @@ class Popen(object): ...@@ -785,7 +785,11 @@ class Popen(object):
stderr = None stderr = None
if self.stdin: if self.stdin:
if input: if input:
try:
self.stdin.write(input) self.stdin.write(input)
except IOError as e:
if e.errno != errno.EPIPE and e.errno != errno.EINVAL:
raise
self.stdin.close() self.stdin.close()
elif self.stdout: elif self.stdout:
stdout = self.stdout.read() stdout = self.stdout.read()
...@@ -1019,7 +1023,11 @@ class Popen(object): ...@@ -1019,7 +1023,11 @@ class Popen(object):
if self.stdin: if self.stdin:
if input is not None: if input is not None:
try:
self.stdin.write(input) self.stdin.write(input)
except IOError as e:
if e.errno != errno.EPIPE:
raise
self.stdin.close() self.stdin.close()
if self.stdout: if self.stdout:
...@@ -1455,7 +1463,14 @@ class Popen(object): ...@@ -1455,7 +1463,14 @@ class Popen(object):
for fd, mode in ready: for fd, mode in ready:
if mode & select.POLLOUT: if mode & select.POLLOUT:
chunk = input[input_offset : input_offset + _PIPE_BUF] chunk = input[input_offset : input_offset + _PIPE_BUF]
try:
input_offset += os.write(fd, chunk) input_offset += os.write(fd, chunk)
except OSError as e:
if e.errno == errno.EPIPE:
close_unregister_and_remove(fd)
else:
raise
else:
if input_offset >= len(input): if input_offset >= len(input):
close_unregister_and_remove(fd) close_unregister_and_remove(fd)
elif mode & select_POLLIN_POLLPRI: elif mode & select_POLLIN_POLLPRI:
...@@ -1499,7 +1514,15 @@ class Popen(object): ...@@ -1499,7 +1514,15 @@ class Popen(object):
if self.stdin in wlist: if self.stdin in wlist:
chunk = input[input_offset : input_offset + _PIPE_BUF] chunk = input[input_offset : input_offset + _PIPE_BUF]
try:
bytes_written = os.write(self.stdin.fileno(), chunk) bytes_written = os.write(self.stdin.fileno(), chunk)
except OSError as e:
if e.errno == errno.EPIPE:
self.stdin.close()
write_set.remove(self.stdin)
else:
raise
else:
input_offset += bytes_written input_offset += bytes_written
if input_offset >= len(input): if input_offset >= len(input):
self.stdin.close() self.stdin.close()
......
...@@ -626,6 +626,25 @@ class ProcessTestCase(BaseTestCase): ...@@ -626,6 +626,25 @@ class ProcessTestCase(BaseTestCase):
self.assertFalse(os.path.exists(ofname)) self.assertFalse(os.path.exists(ofname))
self.assertFalse(os.path.exists(efname)) self.assertFalse(os.path.exists(efname))
def test_communicate_epipe(self):
# Issue 10963: communicate() should hide EPIPE
p = subprocess.Popen([sys.executable, "-c", 'pass'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.addCleanup(p.stdout.close)
self.addCleanup(p.stderr.close)
self.addCleanup(p.stdin.close)
p.communicate(b"x" * 2**20)
def test_communicate_epipe_only_stdin(self):
# Issue 10963: communicate() should hide EPIPE
p = subprocess.Popen([sys.executable, "-c", 'pass'],
stdin=subprocess.PIPE)
self.addCleanup(p.stdin.close)
time.sleep(2)
p.communicate(b"x" * 2**20)
# context manager # context manager
class _SuppressCoreFiles(object): class _SuppressCoreFiles(object):
......
...@@ -49,6 +49,8 @@ Core and Builtins ...@@ -49,6 +49,8 @@ Core and Builtins
Library Library
------- -------
- Issue #10963: Ensure that subprocess.communicate() never raises EPIPE.
- Issue #11746: Fix SSLContext.load_cert_chain() to accept elliptic curve - Issue #11746: Fix SSLContext.load_cert_chain() to accept elliptic curve
private keys. private keys.
......
/* Generated by typeslots.py $Revision: 87806 $ */ /* Generated by typeslots.py $Revision$ */
0, 0,
0, 0,
offsetof(PyHeapTypeObject, as_mapping.mp_ass_subscript), offsetof(PyHeapTypeObject, as_mapping.mp_ass_subscript),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment