Commit 03768ca1 authored by Tom Niget's avatar Tom Niget

Implement context manager protocol for Popen

parent 7050ad2c
...@@ -212,6 +212,17 @@ class Popen(Subprocess): ...@@ -212,6 +212,17 @@ class Popen(Subprocess):
if getattr(self, k) is not None: if getattr(self, k) is not None:
eintr_wrapper(os.close, v) eintr_wrapper(os.close, v)
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if self.stdin is not None:
self.stdin.close()
if self.stdout is not None:
self.stdout.close()
if self.stderr is not None:
self.stderr.close()
def communicate(self, input: bytes | str = None) -> tuple[bytes, bytes]: def communicate(self, input: bytes | str = None) -> tuple[bytes, bytes]:
"""See Popen.communicate.""" """See Popen.communicate."""
# FIXME: almost verbatim from stdlib version, need to be removed or # FIXME: almost verbatim from stdlib version, need to be removed or
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment