Skip to content

Commit acbba3a

Browse files
committedSep 23, 2017
Fix excepthook handling in standalone scripts
1 parent 34a8c8a commit acbba3a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎python/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from qgis.PyQt.QtCore import QCoreApplication, QLocale, QThread
3232
from qgis.PyQt.QtWidgets import QPushButton, QApplication
33-
from qgis.core import Qgis, QgsExpression, QgsMessageLog, qgsfunction, QgsMessageOutput, QgsWkbTypes, QgsApplication
33+
from qgis.core import Qgis, QgsExpression, QgsMessageLog, qgsfunction, QgsMessageOutput, QgsWkbTypes
3434
from qgis.gui import QgsMessageBar
3535

3636
import sys
@@ -133,7 +133,7 @@ def show_message_log(pop_error=True):
133133

134134

135135
def open_stack_dialog(type, value, tb, msg, pop_error=True):
136-
if pop_error:
136+
if pop_error and iface is not None:
137137
iface.messageBar().popWidget()
138138

139139
if msg is None:
@@ -189,7 +189,7 @@ def open_stack_dialog(type, value, tb, msg, pop_error=True):
189189

190190
def qgis_excepthook(type, value, tb):
191191
# detect if running in the main thread
192-
in_main_thread = QThread.currentThread() == QgsApplication.instance().thread()
192+
in_main_thread = QCoreApplication.instance() is None or QThread.currentThread() == QCoreApplication.instance().thread()
193193

194194
# only use messagebar if running in main thread - otherwise it will crash!
195195
showException(type, value, tb, None, messagebar=in_main_thread)

0 commit comments

Comments
 (0)
Please sign in to comment.