summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2013-12-08 03:12:46 (GMT)
committerGregory P. Smith <greg@krypto.org>2013-12-08 03:12:46 (GMT)
commit774f909489ca1395ba1e3f3a1f3d43495df6cdfe (patch)
tree19aa4184aac613938b75afcc89b2514fb0ba2949
parent6c527cf37f9ca6249f523ef3a59e27e64cc13e87 (diff)
downloadcpython-774f909489ca1395ba1e3f3a1f3d43495df6cdfe.zip
cpython-774f909489ca1395ba1e3f3a1f3d43495df6cdfe.tar.gz
cpython-774f909489ca1395ba1e3f3a1f3d43495df6cdfe.tar.bz2
Fixes issue #19506: Use a memoryview to avoid a data copy when piping data
to stdin within subprocess.Popen.communicate. 5-10% less cpu usage.
-rw-r--r--Lib/subprocess.py7
-rw-r--r--Misc/NEWS3
2 files changed, 8 insertions, 2 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index c3a2788..546a7a0 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1621,6 +1621,9 @@ class Popen(object):
self._save_input(input)
+ if self._input:
+ input_view = memoryview(self._input)
+
while self._fd2file:
timeout = self._remaining_time(endtime)
if timeout is not None and timeout < 0:
@@ -1638,8 +1641,8 @@ class Popen(object):
for fd, mode in ready:
if mode & select.POLLOUT:
- chunk = self._input[self._input_offset :
- self._input_offset + _PIPE_BUF]
+ chunk = input_view[self._input_offset :
+ self._input_offset + _PIPE_BUF]
try:
self._input_offset += os.write(fd, chunk)
except OSError as e:
diff --git a/Misc/NEWS b/Misc/NEWS
index 623e1fe..7064460 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,6 +18,9 @@ Core and Builtins
Library
-------
+- Issue #19506: Use a memoryview to avoid a data copy when piping data
+ to stdin within subprocess.Popen.communicate. 5-10% less cpu usage.
+
- Issue #19839: Fix regression in bz2 module's handling of non-bzip2 data at
EOF, and analogous bug in lzma module.