From 062e78a4f4a47b3c250f2638ba15b5dab2573d49 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Oct 2014 16:13:15 +0530 Subject: [PATCH] Workaround for PyQt behavior change on unhandled exceptions in python slots/virtual methods --- src/calibre/gui2/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 03301c57bc..4787d8e49d 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1132,6 +1132,21 @@ def ensure_app(): if islinux or isbsd: args += ['-platformpluginpath', sys.extensions_location, '-platform', 'headless'] _store_app = QApplication(args) + import traceback + # This is needed because as of PyQt 5.4 if sys.execpthook == + # sys.__excepthook__ PyQt will abort the application on an + # unhandled python exception in a slot or virtual method. Since ensure_app() + # is used in worker processes for background work like rendering html + # or running a headless browser, we circumvent this as I really + # dont feel like going through all the code and making sure no + # unhandled exceptions ever occur. All the actual GUI apps already + # override sys.except_hook with a proper error handler. + def eh(t, v, tb): + try: + traceback.print_exception(t, v, tb, file=sys.stderr) + except: + pass + sys.excepthook = eh def must_use_qt(): ''' This function should be called if you want to use Qt for some non-GUI