I'm creating a pyqgis script. In this script I use the processing.runalg command several times. The problem is that these processes are within a for loop. After several iterations, the error number 24 "too many open file" appears. How can I close the files generated by the processes? Here is an example of the code:
for i in range (1, 13000):
path1 = '/path/to/file1_' + str(i) + '.shp' path2 = '/path/to/file2_' + str(i) + '.shp' path3 = '/path/to/file3_' + str(i) + '.asc' path4 = '/path/to/file4_' + str(i) + '.asc' path5 = '/path/to/file5_' + str(i) + '.shp' path6 = '/path/to/file6_' + str(i) + '.shp' path7 = '/path/to/file7_' + str(i) + '.asc' path8 = '/path/to/file8_' + str(i) + '.asc' processing.runalg('qgis:reprojectlayer', path1,'EPSG:3004',path2) processing.runalg('qgis:reprojectlayer', path5,'EPSG:3004',path6) processing.runalg('saga:cubicsplineapproximation', path2,'field',3.0,20.0,5.0,140.0,'2596187,2675187,4321914,4403914',1000.0,0,path3) processing.runalg('saga:cubicsplineapproximation', path6,'field',3.0,20.0,5.0,140.0,'2596187,2675187,4321914,4403914',1000.0,0,path7) processing.runalg('gdalogr:cliprasterbyextent', path3,'-9999','2611187.7500000000000000,2660187.7500000000000000,4336914.1990000000223517,4388914.1990000000223517',5,4,75.0,6.0,1.0,False,0,False,None,path4) processing.runalg('gdalogr:cliprasterbyextent', path7,'-9999','2611187.7500000000000000,2660187.7500000000000000,4336914.1990000000223517,4388914.1990000000223517',5,4,75.0,6.0,1.0,False,0,False,None,path8) ... ...
output_1 = processing.runalg('qgis:reprojectlayer', path1,'EPSG:3004',path2
, then after this line adddel output_1
)? Another approach could be to load the result of each process and then remove them all at the end of each iteration (i.e.QgsMapLayerRegistry.instance().removeMapLayers([layers.id()])