Skip to content

Commit

Permalink
re-introduce looping over all lines in buffer before attempting QA
Browse files Browse the repository at this point in the history
  • Loading branch information
lexming committed Feb 7, 2025
1 parent 4bd36d8 commit badd1f6
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions easybuild/tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,7 @@ def to_cmd_str(cmd):
stdin = stdin.encode()

if stream_output or qa_patterns:
print_msg(f"(streaming) output for command '{cmd_str}':")

# make stdout, stderr, stdin non-blocking files
# enable non-blocking access to stdout, stderr, stdin
channels = [channel for channel in (proc.stdout, proc.stdin, proc.stderr) if channel is not None]
for channel in channels:
os.set_blocking(channel.fileno(), False)
Expand All @@ -528,16 +526,14 @@ def to_cmd_str(cmd):

while exit_code is None:
# collect output line by line, while checking for questions to answer (if qa_patterns is provided)
more_stdout = proc.stdout.readline()
if more_stdout:
_log.debug(f"Obtained more stdout: {more_stdout.decode(errors='ignore').rstrip()}")
stdout += more_stdout
for line in iter(proc.stdout.readline, b''):
_log.debug(f"Captured stdout: {line.decode(errors='ignore').rstrip()}")
stdout += line

# note: we assume that there won't be any questions in stderr output
if split_stderr:
more_stderr = proc.stderr.readline()
if more_stderr:
stderr += more_stderr
for line in iter(proc.stderr.readline, b''):
stderr += line

if qa_patterns:
# only check for question patterns if additional output is available
Expand All @@ -556,17 +552,16 @@ def to_cmd_str(cmd):
error_msg = "No matching questions found for current command output, "
error_msg += f"giving up after {qa_timeout} seconds!"
raise EasyBuildError(error_msg)
else:
_log.debug(f"{time_no_match:0.1f} seconds without match in output of interactive shell command")
_log.debug(f"{time_no_match:0.1f} seconds without match in output of interactive shell command")

time.sleep(check_interval_secs)

exit_code = proc.poll()

# collect last bit of output once processed has exited
more_stdout = proc.stdout.read() or b''
_log.debug(f"Obtained last stdout: {more_stdout.decode(errors='ignore').rstrip()}")
stdout += more_stdout
for line in iter(proc.stdout.readline, b''):
_log.debug(f"Captured stdout: {line.decode(errors='ignore').rstrip()}")
stdout += line
if split_stderr:
stderr += proc.stderr.read() or b''
else:
Expand Down

0 comments on commit badd1f6

Please sign in to comment.