Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(43)

Side by Side Diff: Lib/subprocess.py

Issue 19506: subprocess.communicate() should use a memoryview
Patch Set: Created 6 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # subprocess - Subprocesses with accessible I/O streams 1 # subprocess - Subprocesses with accessible I/O streams
2 # 2 #
3 # For more information about this module, see PEP 324. 3 # For more information about this module, see PEP 324.
4 # 4 #
5 # Copyright (c) 2003-2005 by Peter Astrand <astrand@lysator.liu.se> 5 # Copyright (c) 2003-2005 by Peter Astrand <astrand@lysator.liu.se>
6 # 6 #
7 # Licensed to PSF under a Contributor Agreement. 7 # Licensed to PSF under a Contributor Agreement.
8 # See http://www.python.org/2.4/license for licensing details. 8 # See http://www.python.org/2.4/license for licensing details.
9 9
10 r"""subprocess - Subprocesses with accessible I/O streams 10 r"""subprocess - Subprocesses with accessible I/O streams
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 self._fileobj2output[self.stdout] = [] 1547 self._fileobj2output[self.stdout] = []
1548 if self.stderr: 1548 if self.stderr:
1549 self._fileobj2output[self.stderr] = [] 1549 self._fileobj2output[self.stderr] = []
1550 1550
1551 if self.stdout: 1551 if self.stdout:
1552 stdout = self._fileobj2output[self.stdout] 1552 stdout = self._fileobj2output[self.stdout]
1553 if self.stderr: 1553 if self.stderr:
1554 stderr = self._fileobj2output[self.stderr] 1554 stderr = self._fileobj2output[self.stderr]
1555 1555
1556 self._save_input(input) 1556 self._save_input(input)
1557
1558 # use a memoryview to avoid memory copies
1559 if input:
1560 input_view = memoryview(self._input)
1557 1561
1558 with _PopenSelector() as selector: 1562 with _PopenSelector() as selector:
1559 if self.stdin and input: 1563 if self.stdin and input:
1560 selector.register(self.stdin, selectors.EVENT_WRITE) 1564 selector.register(self.stdin, selectors.EVENT_WRITE)
1561 if self.stdout: 1565 if self.stdout:
1562 selector.register(self.stdout, selectors.EVENT_READ) 1566 selector.register(self.stdout, selectors.EVENT_READ)
1563 if self.stderr: 1567 if self.stderr:
1564 selector.register(self.stderr, selectors.EVENT_READ) 1568 selector.register(self.stderr, selectors.EVENT_READ)
1565 1569
1566 while selector.get_map(): 1570 while selector.get_map():
1567 timeout = self._remaining_time(endtime) 1571 timeout = self._remaining_time(endtime)
1568 if timeout is not None and timeout < 0: 1572 if timeout is not None and timeout < 0:
1569 raise TimeoutExpired(self.args, orig_timeout) 1573 raise TimeoutExpired(self.args, orig_timeout)
1570 1574
1571 ready = selector.select(timeout) 1575 ready = selector.select(timeout)
1572 self._check_timeout(endtime, orig_timeout) 1576 self._check_timeout(endtime, orig_timeout)
1573 1577
1574 # XXX Rewrite these to use non-blocking I/O on the file 1578 # XXX Rewrite these to use non-blocking I/O on the file
1575 # objects; they are no longer using C stdio! 1579 # objects; they are no longer using C stdio!
1576 1580
1577 for key, events in ready: 1581 for key, events in ready:
1578 if key.fileobj is self.stdin: 1582 if key.fileobj is self.stdin:
1579 chunk = self._input[self._input_offset : 1583 chunk = input_view[self._input_offset :
1580 self._input_offset + _PIPE_BUF] 1584 self._input_offset + _PIPE_BUF]
1581 try: 1585 try:
1582 self._input_offset += os.write(key.fd, chunk) 1586 self._input_offset += os.write(key.fd, chunk)
1583 except OSError as e: 1587 except OSError as e:
1584 if e.errno == errno.EPIPE: 1588 if e.errno == errno.EPIPE:
1585 selector.unregister(key.fileobj) 1589 selector.unregister(key.fileobj)
1586 key.fileobj.close() 1590 key.fileobj.close()
1587 else: 1591 else:
1588 raise 1592 raise
1589 else: 1593 else:
1590 if self._input_offset >= len(self._input): 1594 if self._input_offset >= len(self._input):
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 1640
1637 def terminate(self): 1641 def terminate(self):
1638 """Terminate the process with SIGTERM 1642 """Terminate the process with SIGTERM
1639 """ 1643 """
1640 self.send_signal(signal.SIGTERM) 1644 self.send_signal(signal.SIGTERM)
1641 1645
1642 def kill(self): 1646 def kill(self):
1643 """Kill the process with SIGKILL 1647 """Kill the process with SIGKILL
1644 """ 1648 """
1645 self.send_signal(signal.SIGKILL) 1649 self.send_signal(signal.SIGKILL)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+