Skip to content

Commit a209b95

Browse files
committed
Make sure proc.stdout gets always closed in complete_cmd
1 parent 176477d commit a209b95

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

easybuild/tools/run.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -316,21 +316,24 @@ def complete_cmd(proc, cmd, owd, start_time, cmd_log, log_ok=True, log_all=False
316316

317317
stdouterr = output
318318

319-
ec = proc.poll()
320-
while ec is None:
321-
# need to read from time to time.
322-
# - otherwise the stdout/stderr buffer gets filled and it all stops working
323-
output = get_output_from_process(proc, read_size=read_size)
324-
if cmd_log:
325-
cmd_log.write(output)
326-
if stream_output:
327-
sys.stdout.write(output)
328-
stdouterr += output
319+
try:
329320
ec = proc.poll()
321+
while ec is None:
322+
# need to read from time to time.
323+
# - otherwise the stdout/stderr buffer gets filled and it all stops working
324+
output = get_output_from_process(proc, read_size=read_size)
325+
if cmd_log:
326+
cmd_log.write(output)
327+
if stream_output:
328+
sys.stdout.write(output)
329+
stdouterr += output
330+
ec = proc.poll()
331+
332+
# read remaining data (all of it)
333+
output = get_output_from_process(proc)
334+
finally:
335+
proc.stdout.close()
330336

331-
# read remaining data (all of it)
332-
output = get_output_from_process(proc)
333-
proc.stdout.close()
334337
if cmd_log:
335338
cmd_log.write(output)
336339
cmd_log.close()

0 commit comments

Comments
 (0)