From 14c2602517d5ae64f9043e3d2688e6a358a92966 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Tue, 23 Apr 2024 11:43:32 +0200 Subject: [PATCH] Only register sys.excepthook if the app actually started Without this patch, when running tests the crash message box may be displayed. With those changes, it will be displayed only if the app was actually started. --- picard/__init__.py | 12 ++++++------ picard/tagger.py | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/picard/__init__.py b/picard/__init__.py index e60db67457..695b7240fa 100644 --- a/picard/__init__.py +++ b/picard/__init__.py @@ -132,10 +132,10 @@ def crash_handler(exc: Exception = None): app.quit() -def _global_exception_handler(exctype, value, traceback): - from picard import crash_handler - crash_handler(exc=value) - sys.__excepthook__(exctype, value, traceback) +def register_excepthook(): + def _global_exception_handler(exctype, value, traceback): + from picard import crash_handler + crash_handler(exc=value) + sys.__excepthook__(exctype, value, traceback) - -sys.excepthook = _global_exception_handler + sys.excepthook = _global_exception_handler diff --git a/picard/tagger.py b/picard/tagger.py index 4c64d47afc..edf8a6dd6c 100644 --- a/picard/tagger.py +++ b/picard/tagger.py @@ -73,6 +73,7 @@ PICARD_ORG_NAME, acoustid, log, + register_excepthook, ) from picard.acoustid.manager import AcoustIDManager from picard.album import ( @@ -1509,6 +1510,8 @@ def process_picard_args(): def main(localedir=None, autoupdate=True): + register_excepthook() + # Some libs (ie. Phonon) require those to be set QtWidgets.QApplication.setApplicationName(PICARD_APP_NAME) QtWidgets.QApplication.setOrganizationName(PICARD_ORG_NAME)