From b52b2107356d24fe7dd8a995122ad5254a7d056e Mon Sep 17 00:00:00 2001 From: Peter Story Date: Wed, 3 Jul 2024 12:58:24 -0400 Subject: [PATCH] Don't display KeyboardInterrupt errors For #19 --- src/pydiode/gui/common.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/pydiode/gui/common.py b/src/pydiode/gui/common.py index 562bdff..8905d9d 100755 --- a/src/pydiode/gui/common.py +++ b/src/pydiode/gui/common.py @@ -10,6 +10,15 @@ def get_process_errors(name_popen): """ Get a error message describing subprocesses that exited irregularly. + An error shouldn't be described if: + - The process exited normally (exit code 0) + - The user requested cancellation (KeyboardInterrupt in stderr) + + SIGINT is used when the user presses a "Cancel" button (exit code -2). + SIGTERM is issued when subprocesses are stuck (exit code -15). + However, when subprocesses are run from PyInstaller, all non-regular exits + receive code -1. Thus, we also check stderr. + :param name_popen: A list of tuples. Each tuple contains the process name and the subprocess.Popen object. All processes have terminated. @@ -18,14 +27,11 @@ def get_process_errors(name_popen): """ error_msgs = [] for name, popen in name_popen: - # Ignore: - # -2: SIGINT, possibly from user-initiated cancellation. - # 0: normal exit. - # - # Show all other exit codes, including: - # -15: SIGTERM, possibly from stuck subprocesses. - if popen.returncode not in {-2, 0}: - trimmed_stderr = popen.stderr.read().decode("utf-8").strip() + trimmed_stderr = popen.stderr.read().decode("utf-8").strip() + # Show errors if: + if popen.returncode != 0 and not trimmed_stderr.endswith( + "KeyboardInterrupt" + ): error_msg = f'"{name}" exited with code {popen.returncode}' if trimmed_stderr: error_msg += f' and stderr "{trimmed_stderr}"'