2

I have this error when I run some of my python scripts. It does not always occur. It always happens at the END of the script, (all script actions finish!!)

I mainly need to fix it because it is annoying and it prevents me from stringing separate scripts together.

The traceback I get is:

Traceback (most recent call last):
          File "C:/QGIS/apps/qgis/./python/plugins\processing\core\GeoAlgorithm.py", line 203, in execute
            self.processAlgorithm(progress)
          File "C:/QGIS/apps/qgis/./python/plugins\processing\script\ScriptAlgorithm.py", line 378, in processAlgorithm
            exec((script), ns)
          File "<string>", line 146, in <module>
        RuntimeError: wrapped C/C++ object of type QProgressBar has been deleted

However the line it refers to does not seem to make any sense:

error2 = QgsVectorFileWriter.writeAsVectorFormat(bufflayer, buffdef, "CP1250", None, "ESRI Shapefile")

Note that this and all of the python after this command always run just fine. Any thoughts?

5

Try adding the keyword progress=None to your call, i.e. error2 = QgsVectorFileWriter.writeAsVectorFormat(bufflayer, buffdef, "CP1250", None, "ESRI Shapefile", progress=None) I have not tested this in your case, but it worked for me when calling processing algorithms from script (processing.runalg()).

Edit/summary:

Apparently, the main culprit for wonky script behavior is the progress bar that comes with processing algorithms. Your best bet is to add the keyword progress=None to every processing.runalg() call you make. As an extra measure, check the source code of any algorithms you use in your script for calls they might make to other algorithms and add progress=None to those as well.

  • I'll give it a try! – A.A Jul 28 '17 at 17:56
  • No luck: it doesn't work for the QgsVectorFileWriter: it does not have that option. I will look inside the process.runalg for that option though... – A.A Jul 30 '17 at 10:54
  • OK - your idea is CORRECT! but the implementation slightly off. – A.A Jul 30 '17 at 14:05
  • processing.runalg('script:scriptname', progress=None) DOES solve the problem!!! Thanks so much! You have saved me from a problem that has been plaguing me for 6 months! Automation action!! – A.A Jul 30 '17 at 14:06
  • 1
    Everything I am calling is something that I wrote myself, so I know I am not calling another from inside. (my top level scripts literally are just calls to my subscripts for automation purposes) In any case - some of the errors were fixed by removing any and all calls to progress bar in the scripts. I think I have managed to resolve all of the issues except for one and it is not a very critical item. Thanks a lot for your help! – A.A Aug 6 '17 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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