From 50ae49c0ec817748a666724bfaef65c0ed1a51d5 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby <pierre-antoine.rouby@inrae.fr> Date: Wed, 17 Apr 2024 12:17:25 +0200 Subject: [PATCH] Windows: Fix UTF-8 en/decode. --- src/Solver/CommandLine.py | 17 ++++++++++------- src/View/RunSolver/Window.py | 11 +++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Solver/CommandLine.py b/src/Solver/CommandLine.py index 86b32442..c72cf735 100644 --- a/src/Solver/CommandLine.py +++ b/src/Solver/CommandLine.py @@ -20,7 +20,7 @@ import os import logging from datetime import datetime -from tools import timer, parse_command_line, get_version +from tools import timer, parse_command_line, get_version, logger_exception try: # Installation allow Unix-like signal @@ -271,12 +271,15 @@ class CommandLineSolver(AbstractSolver): return True def _data_ready(self): - # Read process output and put lines in queue - s = self._process.readAll().data().decode() - - if self._output is not None: - for x in s.split('\n'): - self._output.put(x) + try: + # Read process output and put lines in queue + s = self._process.readAll().data().decode('utf-8', "replace") + + if self._output is not None: + for x in s.split('\n'): + self._output.put(x) + except Exception as e: + logger_exception(e) def _finished(self, study, exit_code, exit_status): if self._output is not None: diff --git a/src/View/RunSolver/Window.py b/src/View/RunSolver/Window.py index dc1141d6..6c55ea6a 100644 --- a/src/View/RunSolver/Window.py +++ b/src/View/RunSolver/Window.py @@ -296,10 +296,13 @@ class SolverLogWindow(PamhyrWindow): while self._output.qsize() != 0: s = self._output.get() - if type(s) is str and "[ERROR]" in s: - self._log(s, color="red") - else: - self._log(s) + try: + if type(s) is str and "[ERROR]" in s: + self._log(s.encode("utf-8"), color="red") + else: + self._log(s) + except Exception as e: + logger_exception(e) #################### # Process controle # -- GitLab