From fb210abcd0133586b0b96bbb99678b6ea8491ef0 Mon Sep 17 00:00:00 2001 From: Ben Richard <143630488+benrichard-amd@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:27:55 -0400 Subject: [PATCH] Skip output lines that have UTF8 decoding error (#441) * Avoid crash if non-UTF8 character is encountered in output Signed-off-by: benrichard-amd * Ignore lines with non-UTF-8 characters. Do not print error. Signed-off-by: benrichard-amd * Remove trailing whitespace Signed-off-by: benrichard-amd --------- Signed-off-by: benrichard-amd --- src/utils/utils.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index a4b1a10b33..4175fdab2e 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -205,14 +205,18 @@ def capture_subprocess_output(subprocess_args, new_env=None, profileMode=False): buf = io.StringIO() def handle_output(stream, mask): - # Because the process' output is line buffered, there's only ever one - # line to read when this function is called - line = stream.readline() - buf.write(line) - if profileMode: - console_log(rocprof_cmd, line.strip(), indent_level=1) - else: - console_log(line.strip()) + try: + # Because the process' output is line buffered, there's only ever one + # line to read when this function is called + line = stream.readline() + buf.write(line) + if profileMode: + console_log(rocprof_cmd, line.strip(), indent_level=1) + else: + console_log(line.strip()) + except UnicodeDecodeError: + # Skip this line + pass # Register callback for an "available for read" event from subprocess' stdout stream selector = selectors.DefaultSelector()