When I run the script below in Python Terminal at QGIS 2.18.17 (Linux Mint 19) it always crash after doing 73 iterations at the 2nd for loop from the script. Could anyone explain why this happens and could suggest how can I fix it?

For now, the way that I found to deal with this problem is to close QGIS, open it and run the script again from the item that it stopped. But when you have more than 2000 itens in a list of a for loop this can be quite annoying.

import processing
import os
import pandas as pd
wd = "/home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/up_centroides/split"
lc = list()
for file in os.listdir(wd):
    if file.endswith(".shp"):
        lc.append (wd+"/"+file)
drenagem = QgsVectorLayer('/home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/redes_drenagem/rio_7.shp', '','ogr')
fim = QgsVectorLayer('/home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/fozes/foz_1.shp', '','ogr')
ext = drenagem.extent()
xmin = ext.xMinimum()
xmax = ext.xMaximum()
ymin = ext.yMinimum()
ymax = ext.yMaximum()
coords = "%f,%f,%f,%f" %(xmin, xmax, ymin, ymax)
ups = "/home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/up/up_mata.shp"
pasta_intermediarios = "/home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/v_net_distance"
p = 1
## 2nd FOR LOOP ##
for pto in lc:
    nome = os.path.basename(pto)
    nome = nome.replace(".shp","")
    nome = nome.replace("up_centroide_diss_COD_","")
    v_dist= pasta_intermediarios+"/v_dist_"+nome+".shp"
    disol= pasta_intermediarios+"/v_disol_"+nome+".shp"
    explo= pasta_intermediarios+"/v_explo_"+nome+".shp"
    points= pasta_intermediarios+"/v_points_"+nome+".shp"
    inter = pasta_intermediarios+"/v_inter_"+nome+".shp"
    inter_shp = QgsVectorLayer(inter,'',"ogr")
    list_up = list()
    for feature in inter_shp.getFeatures():
        up = int(feature["UP_UC"])
        if up not in list_up:
            list_up.append (up)
    jusante = list_up[:]
    del jusante[0]
    df = pd.DataFrame(jusante,list_up)
    nome = os.path.basename(pto)
    nome = nome.replace(".shp",".csv")
    nome = nome.replace("up_centroide_diss_COD_","")
    path = os.path.dirname(v_dist)
    files_to_del = []
    for r, d, f in os.walk(path):
        for file in f:
            files_to_del.append(os.path.join(r, file))
    for file in files_to_del:
    print p, "de", len(lc)
    print nome,"done"
    p = p+1

This is the message that I get.

Unable to execute algorithm
Wrong parameter value: /home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/v_net_distance/v_dist_UP_764949.shp
Unable to execute algorithm
Wrong parameter value: /home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/v_net_distance/v_disol_UP_764949.shp
Unable to execute algorithm
Wrong parameter value: /home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/v_net_distance/v_explo_UP_764949.shp
Unable to execute algorithm
Wrong parameter value: /home/tiago/Documentos/PRIM_Mineracao/mata_atlantica/v_net_distance/v_points_UP_764949.shp
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/tmp/tmp2K40DP.py", line 42, in <module>
    del jusante[0]
IndexError: list assignment index out of range
  • Looks like inter_shp.getFeatures() returns nothing for one of your items - empty intersection in earlier step?
    – SMiller
    Jun 9, 2019 at 15:22
  • But there is an intersection, because when I close Qgis after this error, reopen it, the script runs from the item where it had stopped normally. @smiller.
    – tiago
    Jun 9, 2019 at 20:13
  • Please include the result of diagnostic print statements in your code. My traceback: jusante[0] doesn't exist. jusante is copy of list_up. list_up created by inter_shp.getFeatures(). inter_shp is a QgsVectorLayer of inter, which is from the intersection process.
    – SMiller
    Jun 10, 2019 at 13:18

1 Answer 1


After taking a look at a similar question:

How to close open files after processing.runlag() command (Qgis: Error No 24)

And at this site:


I could manage it setting the number of files opened by process using ulimit command at Linux terminal before opening Qgis at the same terminal.

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.