twister: handler: open files using with statement
Use with statement to open stdout/stderr and resolve current warning when running twister: ResourceWarning: unclosed file.... Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
ef6f804d8f
commit
072a430cea
1 changed files with 7 additions and 9 deletions
|
@ -354,12 +354,9 @@ class BinaryHandler(Handler):
|
||||||
return
|
return
|
||||||
|
|
||||||
stderr_log = f"{self.instance.build_dir}/handler_stderr.log"
|
stderr_log = f"{self.instance.build_dir}/handler_stderr.log"
|
||||||
with (
|
with open(stderr_log, "w+") as stderr_log_fp, subprocess.Popen(
|
||||||
open(stderr_log, "w+") as stderr_log_fp,
|
command, stdout=subprocess.PIPE, stderr=stderr_log_fp, cwd=self.build_dir, env=env
|
||||||
subprocess.Popen(
|
) as proc:
|
||||||
command, stdout=subprocess.PIPE, stderr=stderr_log_fp, cwd=self.build_dir, env=env
|
|
||||||
) as proc,
|
|
||||||
):
|
|
||||||
logger.debug(f"Spawning BinaryHandler Thread for {self.name}")
|
logger.debug(f"Spawning BinaryHandler Thread for {self.name}")
|
||||||
t = threading.Thread(target=self._output_handler, args=(proc, harness,), daemon=True)
|
t = threading.Thread(target=self._output_handler, args=(proc, harness,), daemon=True)
|
||||||
t.start()
|
t.start()
|
||||||
|
@ -1102,10 +1099,11 @@ class QEMUHandler(Handler):
|
||||||
is_timeout = False
|
is_timeout = False
|
||||||
qemu_pid = None
|
qemu_pid = None
|
||||||
|
|
||||||
with subprocess.Popen(
|
with open(self.stdout_fn, "w") as stdout_fp, \
|
||||||
|
open(self.stderr_fn, "w") as stderr_fp, subprocess.Popen(
|
||||||
command,
|
command,
|
||||||
stdout=open(self.stdout_fn, "w"),
|
stdout=stdout_fp,
|
||||||
stderr=open(self.stderr_fn, "w"),
|
stderr=stderr_fp,
|
||||||
cwd=self.build_dir
|
cwd=self.build_dir
|
||||||
) as proc:
|
) as proc:
|
||||||
logger.debug(f"Spawning QEMUHandler Thread for {self.name}")
|
logger.debug(f"Spawning QEMUHandler Thread for {self.name}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue