From dc267b90182e9bce65da4e8a9c80146c2ad1f9df Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Mon, 1 Apr 2024 13:11:05 -0400 Subject: [PATCH] Set encoding to utf-8 for subprocesses --- backend/src/dependencies/store.py | 10 ++++++---- backend/src/server_process_helper.py | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/src/dependencies/store.py b/backend/src/dependencies/store.py index 5e202e59f..2747fc840 100644 --- a/backend/src/dependencies/store.py +++ b/backend/src/dependencies/store.py @@ -165,13 +165,14 @@ def get_progress_amount(): ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + encoding="utf-8", ) installing_name = "Unknown" while True: nextline = process.stdout.readline() # type: ignore - if nextline == b"" and process.poll() is not None: + if process.poll() is not None: break - line = nextline.decode("utf-8").strip() + line = nextline.strip() if not line: continue @@ -298,13 +299,14 @@ def get_progress_amount(): ], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + encoding="utf-8", ) uninstalling_name = "Unknown" while True: nextline = process.stdout.readline() # type: ignore - if nextline == b"" and process.poll() is not None: + if process.poll() is not None: break - line = nextline.decode("utf-8").strip() + line = nextline.strip() if not line: continue diff --git a/backend/src/server_process_helper.py b/backend/src/server_process_helper.py index 5694ef774..c07532f1d 100644 --- a/backend/src/server_process_helper.py +++ b/backend/src/server_process_helper.py @@ -42,6 +42,7 @@ def __init__(self, flags: list[str]): stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + encoding="utf-8", ) self._stop_event = threading.Event() @@ -63,7 +64,7 @@ def _read_output(self): for line in self._process.stdout: if self._stop_event.is_set(): break - stripped_line = line.decode().rstrip() + stripped_line = line.rstrip() match_obj = re.match(SANIC_LOG_REGEX, stripped_line) if match_obj is not None: log_level, message = match_obj.groups()