diff options
author | Helmut Grohne <helmut@subdivi.de> | 2022-06-23 17:26:18 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2022-06-23 17:26:18 +0200 |
commit | 68e2e0a5f29e011d2304d03cf26f10e7e8846d3d (patch) | |
tree | 14d78646f4756ff0656d2e78b83c3f5448ee472d /mdbp/streamapi.py | |
parent | 3f7e63d35c9f47fd9bb1d6e68ff2dd1a09e76920 (diff) | |
download | mdbp-68e2e0a5f29e011d2304d03cf26f10e7e8846d3d.tar.gz |
streamapi: use Popen as a context manager
Diffstat (limited to 'mdbp/streamapi.py')
-rw-r--r-- | mdbp/streamapi.py | 15 |
1 files 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: |