[rtems-central commit] util: Use with for resource-allocating operation
Sebastian Huber
sebh at rtems.org
Mon Apr 11 13:48:27 UTC 2022
Module: rtems-central
Branch: master
Commit: 89c4a1efebaf4a6d142f4e02c07256127ffc7ea1
Changeset: http://git.rtems.org/rtems-central/commit/?id=89c4a1efebaf4a6d142f4e02c07256127ffc7ea1
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Apr 11 15:50:23 2022 +0200
util: Use with for resource-allocating operation
---
rtemsspec/util.py | 36 ++++++++++++++++++------------------
1 file 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()
More information about the vc
mailing list