diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-04-11 15:50:23 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-04-11 15:51:06 +0200 |
commit | 89c4a1efebaf4a6d142f4e02c07256127ffc7ea1 (patch) | |
tree | 750e23b728d59297488801fc50b9070bcb9df963 /rtemsspec | |
parent | items: Add ItemGetValueContext.arg() (diff) | |
download | rtems-central-89c4a1efebaf4a6d142f4e02c07256127ffc7ea1.tar.bz2 |
util: Use with for resource-allocating operation
Diffstat (limited to 'rtemsspec')
-rw-r--r-- | rtemsspec/util.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/rtemsspec/util.py b/rtemsspec/util.py index bf07b5fa..e4c033db 100644 --- a/rtemsspec/util.py +++ b/rtemsspec/util.py @@ -78,21 +78,21 @@ def run_command(args: List[str], exit status of the subprocess. """ logging.info("run in '%s': %s", cwd, " ".join(f"'{arg}'" for arg in args)) - task = subprocess.Popen(args, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, - cwd=cwd, - env=env) - assert task.stdout is not None - while True: - raw_line = task.stdout.readline() - if raw_line: - line = raw_line.decode("utf-8").rstrip() - if stdout is None: - logging.debug("%s", line) - else: - stdout.append(line) - elif task.poll() is not None: - break - return task.wait() + with subprocess.Popen(args, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + cwd=cwd, + env=env) as task: + assert task.stdout is not None + while True: + raw_line = task.stdout.readline() + if raw_line: + line = raw_line.decode("utf-8").rstrip() + if stdout is None: + logging.debug("%s", line) + else: + stdout.append(line) + elif task.poll() is not None: + break + return task.wait() |