diff --git a/python/utils.py b/python/utils.py index 241af1ed48e..04bcd0e9331 100644 --- a/python/utils.py +++ b/python/utils.py @@ -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)