Fix excepthook handling in standalone scripts

This commit is contained in:
Nyall Dawson 2017-08-15 16:59:16 +10:00
parent 34a8c8aab8
commit acbba3a387

View File

@ -30,7 +30,7 @@ QGIS utilities module
from qgis.PyQt.QtCore import QCoreApplication, QLocale, QThread
from qgis.PyQt.QtWidgets import QPushButton, QApplication
from qgis.core import Qgis, QgsExpression, QgsMessageLog, qgsfunction, QgsMessageOutput, QgsWkbTypes, QgsApplication
from qgis.core import Qgis, QgsExpression, QgsMessageLog, qgsfunction, QgsMessageOutput, QgsWkbTypes
from qgis.gui import QgsMessageBar
import sys
@ -133,7 +133,7 @@ def show_message_log(pop_error=True):
def open_stack_dialog(type, value, tb, msg, pop_error=True):
if pop_error:
if pop_error and iface is not None:
iface.messageBar().popWidget()
if msg is None:
@ -189,7 +189,7 @@ def open_stack_dialog(type, value, tb, msg, pop_error=True):
def qgis_excepthook(type, value, tb):
# detect if running in the main thread
in_main_thread = QThread.currentThread() == QgsApplication.instance().thread()
in_main_thread = QCoreApplication.instance() is None or QThread.currentThread() == QCoreApplication.instance().thread()
# only use messagebar if running in main thread - otherwise it will crash!
showException(type, value, tb, None, messagebar=in_main_thread)