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.
This commit is contained in:
commit
5ca129b8f0
|
@ -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:
|
||||
|
|
|
@ -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 #19876: selectors unregister() no longer raises ValueError or OSError
|
||||
if the FD is closed (as long as it was registered).
|
||||
|
||||
|
|
Loading…
Reference in New Issue