I am using the PyQGIS template from @underdark for showing the crash. Her script is running like a charm, but as soon as I add a print("finished...") - call in her code, QGIS 3.4 Madeira crashes.

You can look up her code on this site: @underdarks class template for python processing scripts

And in the following code snippet you can see the part where I added the print()-call:

    def processAlgorithm(self, parameters, context, feedback):
    source = self.parameterAsSource(parameters, self.INPUT, context)
    (sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
                                           source.fields(), source.wkbType(), source.sourceCrs())

    features = source.getFeatures(QgsFeatureRequest())
    for feat in features:
        out_feat = QgsFeature()
        sink.addFeature(out_feat, QgsFeatureSink.FastInsert)

    print("finished ...")  # QGIS3 crashes after this line
    return {self.OUTPUT: dest_id}

The crash looks like this (please note that the string "finished..." has been printed into the console before QGIS crashed):

enter image description here

Any suggestions?

1 Answer 1


Don't use print in QGIS3 processing algorithms. Explanation from QGIS processing guide draft:

Give feedback via the feedback object, not directly to QgsMessageLog (and avoid print statements - these are dangerous to use for algorithms which may be executed in a background thread!).

Replace print with:

feedback.pushInfo("finished ...")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.