Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mlcube logging small fixes #541

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions cli/medperf/entities/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ def _set_image_hash_from_registry(self):
cmd += f" --platform={config.platform} --output-file {tmp_out_yaml}"
logging.info(f"Running MLCube command: {cmd}")
with pexpect.spawn(cmd, timeout=config.mlcube_inspect_timeout) as proc:
proc_stdout = proc.read()
logging.debug(proc_stdout)
combine_proc_sp_text(proc)
if proc.exitstatus != 0:
raise ExecutionError("There was an error while inspecting the image hash")
with open(tmp_out_yaml) as f:
Expand All @@ -268,10 +267,9 @@ def _get_image_from_registry(self):
cmd += f" -Psingularity.image={self._converted_singularity_image_name}"
logging.info(f"Running MLCube command: {cmd}")
with pexpect.spawn(cmd, timeout=config.mlcube_configure_timeout) as proc:
proc_out = proc.read()
combine_proc_sp_text(proc)
if proc.exitstatus != 0:
raise ExecutionError("There was an error while retrieving the MLCube image")
logging.debug(proc_out)

def download_config_files(self):
try:
Expand Down Expand Up @@ -366,9 +364,7 @@ def run(
with pexpect.spawn(cmd, timeout=timeout) as proc:
proc_out = combine_proc_sp_text(proc)

if output_logs is None:
logging.debug(proc_out)
else:
if output_logs is not None:
with open(output_logs, "w") as f:
f.write(proc_out)
if proc.exitstatus != 0:
Expand Down
15 changes: 9 additions & 6 deletions cli/medperf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ def combine_proc_sp_text(proc: spawn) -> str:
"""

ui = config.ui
static_text = ui.text
proc_out = ""
break_ = False
log_filter = _MLCubeOutputFilter(proc.pid)
Expand All @@ -267,18 +266,22 @@ def combine_proc_sp_text(proc: spawn) -> str:
line = proc.readline()
except TIMEOUT:
logging.error("Process timed out")
logging.debug(proc_out)
raise ExecutionError("Process timed out")
line = line.decode("utf-8", "ignore")

if not line:
continue

if log_filter.check_line(line):
logging.debug(line)
else:
proc_out += line
# Always log each line just in case the final proc_out
# wasn't logged for some reason
logging.debug(line)
proc_out += line
if not log_filter.check_line(line):
ui.print(f"{Fore.WHITE}{Style.DIM}{line.strip()}{Style.RESET_ALL}")
ui.text = static_text

logging.debug("MLCube process finished")
logging.debug(proc_out)
return proc_out


Expand Down
Loading