diff options
author | Gregory P. Smith <greg@krypto.org> | 2013-12-08 03:14:59 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2013-12-08 03:14:59 (GMT) |
commit | 5ca129b8f016668bf914592e58082c452a7ad9b4 (patch) | |
tree | 1cf1a6accd1ff027c55ac5aa0e26c53107a4a845 /Lib/subprocess.py | |
parent | 5c29424f4bae94e32ec7332551f3ccabf2f957dd (diff) | |
parent | 774f909489ca1395ba1e3f3a1f3d43495df6cdfe (diff) | |
download | cpython-5ca129b8f016668bf914592e58082c452a7ad9b4.zip cpython-5ca129b8f016668bf914592e58082c452a7ad9b4.tar.gz cpython-5ca129b8f016668bf914592e58082c452a7ad9b4.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.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 0942d94..e7f39fe 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1562,6 +1562,9 @@ class Popen(object): 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 @@ class Popen(object): 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: |