mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
Fix #10554. Added context manager support to Popen objects.
Added a few common Popen uses to the tests like we've done for a few other instances of adding context managers. Eventually the entire test suite could be converted to use the context manager format.
This commit is contained in:
parent
2d93e6ee63
commit
79cdb661f5
4 changed files with 65 additions and 1 deletions
|
|
@ -697,6 +697,16 @@ class Popen(object):
|
|||
data = data.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
||||
return data.decode(encoding)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
if self.stdout:
|
||||
self.stdout.close()
|
||||
if self.stderr:
|
||||
self.stderr.close()
|
||||
if self.stdin:
|
||||
self.stdin.close()
|
||||
|
||||
def __del__(self, _maxsize=sys.maxsize, _active=_active):
|
||||
if not self._child_created:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue