mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Merge with 3.2
This commit is contained in:
commit
0b9ea93a64
3 changed files with 55 additions and 11 deletions
|
@ -348,6 +348,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 SubprocessError(Exception): pass
|
class SubprocessError(Exception): pass
|
||||||
|
@ -396,7 +397,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
|
||||||
|
|
||||||
|
@ -826,7 +826,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()
|
||||||
|
@ -1104,7 +1108,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()
|
||||||
|
|
||||||
# Wait for the reader threads, or time out. If we time out, the
|
# Wait for the reader threads, or time out. If we time out, the
|
||||||
|
@ -1621,7 +1629,14 @@ class Popen(object):
|
||||||
if mode & select.POLLOUT:
|
if mode & select.POLLOUT:
|
||||||
chunk = self._input[self._input_offset :
|
chunk = self._input[self._input_offset :
|
||||||
self._input_offset + _PIPE_BUF]
|
self._input_offset + _PIPE_BUF]
|
||||||
|
try:
|
||||||
self._input_offset += os.write(fd, chunk)
|
self._input_offset += os.write(fd, chunk)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno == errno.EPIPE:
|
||||||
|
close_unregister_and_remove(fd)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
if self._input_offset >= len(self._input):
|
if self._input_offset >= len(self._input):
|
||||||
close_unregister_and_remove(fd)
|
close_unregister_and_remove(fd)
|
||||||
elif mode & select_POLLIN_POLLPRI:
|
elif mode & select_POLLIN_POLLPRI:
|
||||||
|
@ -1691,7 +1706,15 @@ class Popen(object):
|
||||||
if self.stdin in wlist:
|
if self.stdin in wlist:
|
||||||
chunk = self._input[self._input_offset :
|
chunk = self._input[self._input_offset :
|
||||||
self._input_offset + _PIPE_BUF]
|
self._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()
|
||||||
|
self._write_set.remove(self.stdin)
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
self._input_offset += bytes_written
|
self._input_offset += bytes_written
|
||||||
if self._input_offset >= len(self._input):
|
if self._input_offset >= len(self._input):
|
||||||
self.stdin.close()
|
self.stdin.close()
|
||||||
|
|
|
@ -720,6 +720,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):
|
||||||
|
|
|
@ -94,6 +94,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #10963: Ensure that subprocess.communicate() never raises EPIPE.
|
||||||
|
|
||||||
- Issue #10791: Implement missing method GzipFile.read1(), allowing GzipFile
|
- Issue #10791: Implement missing method GzipFile.read1(), allowing GzipFile
|
||||||
to be wrapped in a TextIOWrapper. Patch by Nadeem Vawda.
|
to be wrapped in a TextIOWrapper. Patch by Nadeem Vawda.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue