[Python-checkins] cpython (merge 3.3 -> default): Fixes issue #19506: Use a memoryview to avoid a data copy when piping data
gregory.p.smith
python-checkins at python.org
Sun Dec 8 04:15:17 CET 2013
http://hg.python.org/cpython/rev/5379bba2fb21
changeset: 87820:5379bba2fb21
parent: 87818:94593dcb195a
parent: 87819:44948f5bdc12
user: Gregory P. Smith <greg at krypto.org>
date: Sat Dec 07 19:14:59 2013 -0800
summary:
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.
files:
Lib/subprocess.py | 7 +++++--
Misc/NEWS | 3 +++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1562,6 +1562,9 @@
self._save_input(input)
+ if self._input:
+ input_view = memoryview(self._input)
+
with _PopenSelector() as selector:
if self.stdin and input:
selector.register(self.stdin, selectors.EVENT_WRITE)
@@ -1583,8 +1586,8 @@
for key, events in ready:
if key.fileobj is self.stdin:
- 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(key.fd, chunk)
except OSError as e:
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -18,6 +18,9 @@
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 #19876: selectors unregister() no longer raises ValueError or OSError
if the FD is closed (as long as it was registered).
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list