qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.29k stars 2.96k forks source link

QGIS crashes when printing to console in separate thread #28378

Closed qgib closed 5 years ago

qgib commented 5 years ago

Author Name: Matthew Jackson (Matthew Jackson) Original Redmine Issue: 20558 Affected QGIS version: 3.4.1 Redmine category:pythonbindings/_sipify


If you run the following in the python console from QGIS 3.x in Windows 10, QGIS will crash every time. I believe this is a regression that began with 3.0, but I no longer have a 2.x version to compare with.

class PrintThread (QThread): completed = pyqtSignal() def init(self ): QThread.init(self) def run (self): print("a message!")

t = PrintThread() t.start()

qgib commented 5 years ago

Author Name: Giovanni Manghi (@gioman)


qgib commented 5 years ago

Author Name: Alessandro Pasotti (@elpaso)


I think this is a won't fix: python printing from a thread will crash for sure.

You should use QgsMessageLog or other means to communicate with the user.

qgib commented 5 years ago

Author Name: Nyall Dawson (@nyalldawson)


It's not a regression - this has always been the case.


qgib commented 5 years ago

Author Name: Juan Manuel Perez (@juanmpd)


Just tried the above code on QGis 2.18.20, and in 2.18 this piece of code didn't cause QGis to crash. I stumbled on this issue while migrating a processing pluging from Qgis 2.18 to Qgis 3.4. Its processing algorithm included some 'print' statements, and I've been forced to remove them for Qgis3 (in Qgis2 they didn't cause any problems).

qgib commented 5 years ago

Author Name: Alessandro Pasotti (@elpaso)


The solution is simple: do not use "print" in a python script in QGIS.