From 774f909489ca1395ba1e3f3a1f3d43495df6cdfe Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sat, 7 Dec 2013 19:12:46 -0800 Subject: 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. --- Lib/subprocess.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Lib/subprocess.py') diff --git a/Lib/subprocess.py b/Lib/subprocess.py index c3a278836c..546a7a0fcd 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: -- cgit v1.2.1