Bug report #20558

QGIS crashes when printing to console in separate thread

Added by Matthew Jackson about 6 years ago. Updated almost 6 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Python bindings / sipify
Affected QGIS version:3.4.1 Regression?:No
Operating System:Windows 10 Easy fix?:No
Pull Request or Patch supplied:No Resolution:wontfix
Crashes QGIS or corrupts data:Yes Copied to github as #:28378

Description

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()

History

#1 Updated by Giovanni Manghi about 6 years ago

  • Category changed from Python plugins to Python bindings / sipify

#2 Updated by Alessandro Pasotti about 6 years ago

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.

#3 Updated by Nyall Dawson about 6 years ago

  • Regression? changed from Yes to No

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

#4 Updated by Juan Manuel Perez almost 6 years ago

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).

#5 Updated by Alessandro Pasotti almost 6 years ago

  • Resolution set to wontfix
  • Status changed from Open to Closed

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

Also available in: Atom PDF