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

Side by Side Diff: Lib/subprocess.py

Issue 26741: subprocess.Popen should emit a ResourceWarning in destructor if the process is still running
Patch Set: Created 3 years, 6 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 | Lib/test/test_subprocess.py » ('j') | Lib/test/test_subprocess.py » ('J')
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 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 if self.stdin: 998 if self.stdin:
999 self.stdin.close() 999 self.stdin.close()
1000 finally: 1000 finally:
1001 # Wait for the process to terminate, to avoid zombies. 1001 # Wait for the process to terminate, to avoid zombies.
1002 self.wait() 1002 self.wait()
1003 1003
1004 def __del__(self, _maxsize=sys.maxsize): 1004 def __del__(self, _maxsize=sys.maxsize):
1005 if not self._child_created: 1005 if not self._child_created:
1006 # We didn't get to successfully create a child process. 1006 # We didn't get to successfully create a child process.
1007 return 1007 return
1008 if self.returncode is None:
1009 warnings.warn("running subprocess %r" % self, ResourceWarning,
1010 source=self)
1008 # In case the child hasn't been waited on, check if it's done. 1011 # In case the child hasn't been waited on, check if it's done.
1009 self._internal_poll(_deadstate=_maxsize) 1012 self._internal_poll(_deadstate=_maxsize)
1010 if self.returncode is None and _active is not None: 1013 if self.returncode is None and _active is not None:
1011 # Child is still running, keep us alive until we can wait on it. 1014 # Child is still running, keep us alive until we can wait on it.
1012 _active.append(self) 1015 _active.append(self)
1013 1016
1014 def _get_devnull(self): 1017 def _get_devnull(self):
1015 if not hasattr(self, '_devnull'): 1018 if not hasattr(self, '_devnull'):
1016 self._devnull = os.open(os.devnull, os.O_RDWR) 1019 self._devnull = os.open(os.devnull, os.O_RDWR)
1017 return self._devnull 1020 return self._devnull
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 while True: 1515 while True:
1513 part = os.read(errpipe_read, 50000) 1516 part = os.read(errpipe_read, 50000)
1514 errpipe_data += part 1517 errpipe_data += part
1515 if not part or len(errpipe_data) > 50000: 1518 if not part or len(errpipe_data) > 50000:
1516 break 1519 break
1517 finally: 1520 finally:
1518 # be sure the FD is closed no matter what 1521 # be sure the FD is closed no matter what
1519 os.close(errpipe_read) 1522 os.close(errpipe_read)
1520 1523
1521 if errpipe_data: 1524 if errpipe_data:
1525 self.returncode = 255
1522 try: 1526 try:
1523 os.waitpid(self.pid, 0) 1527 pid, sts = os.waitpid(self.pid, 0)
1528 if pid == self.pid:
Martin Panter 2016/04/13 04:31:30 Is it possible for this to not be the case, i.e. w
1529 self._handle_exitstatus(sts)
1524 except ChildProcessError: 1530 except ChildProcessError:
1525 pass 1531 pass
1532
1526 try: 1533 try:
1527 exception_name, hex_errno, err_msg = ( 1534 exception_name, hex_errno, err_msg = (
1528 errpipe_data.split(b':', 2)) 1535 errpipe_data.split(b':', 2))
1529 except ValueError: 1536 except ValueError:
1530 exception_name = b'SubprocessError' 1537 exception_name = b'SubprocessError'
1531 hex_errno = b'0' 1538 hex_errno = b'0'
1532 err_msg = (b'Bad exception data from child: ' + 1539 err_msg = (b'Bad exception data from child: ' +
1533 repr(errpipe_data)) 1540 repr(errpipe_data))
1534 child_exception_type = getattr( 1541 child_exception_type = getattr(
1535 builtins, exception_name.decode('ascii'), 1542 builtins, exception_name.decode('ascii'),
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 1779
1773 def terminate(self): 1780 def terminate(self):
1774 """Terminate the process with SIGTERM 1781 """Terminate the process with SIGTERM
1775 """ 1782 """
1776 self.send_signal(signal.SIGTERM) 1783 self.send_signal(signal.SIGTERM)
1777 1784
1778 def kill(self): 1785 def kill(self):
1779 """Kill the process with SIGKILL 1786 """Kill the process with SIGKILL
1780 """ 1787 """
1781 self.send_signal(signal.SIGKILL) 1788 self.send_signal(signal.SIGKILL)
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_subprocess.py » ('j') | Lib/test/test_subprocess.py » ('J')

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