Skip to content

Commit 328593a

Browse files
committed
Close file handles for run_shell_cmd
The stdin/stdout/stderr handles need be closed by calling `communicate`. Otherwise the handles will be leaked and e.g. `test_run_shell_cmd_qa_trace` fails because it may capture a related warning.
1 parent 7325264 commit 328593a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

easybuild/tools/run.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,12 @@ def to_cmd_str(cmd):
570570
exit_code = proc.poll()
571571

572572
# collect last bit of output once processed has exited
573-
for line in iter(proc.stdout.readline, b''):
574-
_log.debug(f"Captured stdout: {line.decode(errors='ignore').rstrip()}")
575-
stdout += line
573+
last_stdout, last_stderr = proc.communicate()
574+
if last_stdout:
575+
_log.debug(f"Captured stdout: {last_stdout.decode(errors='ignore').rstrip()}")
576+
stdout += last_stdout
576577
if split_stderr:
577-
stderr += proc.stderr.read() or b''
578+
stderr += last_stderr or b''
578579
else:
579580
(stdout, stderr) = proc.communicate(input=stdin)
580581

0 commit comments

Comments
 (0)