From 68e2e0a5f29e011d2304d03cf26f10e7e8846d3d Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Thu, 23 Jun 2022 17:26:18 +0200 Subject: streamapi: use Popen as a context manager --- mdbp/streamapi.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mdbp/streamapi.py b/mdbp/streamapi.py index a32761b..e959efc 100644 --- a/mdbp/streamapi.py +++ b/mdbp/streamapi.py @@ -57,13 +57,14 @@ def main() -> None: seenjson = True if not seenjson: raise ValueError("input is an empty tar archive") - proc = subprocess.Popen([*args.command, str(indir / "build.json")], - stdout=sys.stderr - if build["output"].get("log", True) - else subprocess.DEVNULL, - stderr=None if build["output"].get("log", True) - else subprocess.DEVNULL) - code = proc.wait() + with subprocess.Popen( + [*args.command, str(indir / "build.json")], + stdout=sys.stderr if build["output"].get("log", True) + else subprocess.DEVNULL, + stderr=None if build["output"].get("log", True) + else subprocess.DEVNULL + ) as proc: + code = proc.wait() if code != 0: sys.exit(code) with tarfile.open(fileobj=sys.stdout.buffer, mode="w|") as outtar: -- cgit v1.2.3