TransWikia.com

QGIS 3.4 Madeira crashes when calling print()

Geographic Information Systems Asked by applebrown on August 24, 2020

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()
        out_feat.setGeometry(feat.geometry())
        out_feat.setAttributes(feat.attributes())
        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?

One Answer

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

Answered by barteksch on August 24, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP