Tuesday 27 December 2016

qgis - can not delete file after using runalg function


I my plugin I use the runalg function:


processing.runalg("qgis:clip",filepath + "/temp2.shp", Layer, filepath + '/' + layerName)
vlayer = QgsVectorLayer(filepath + '/' + layerName + '.shp',layerName, "ogr")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)

Afterwards I want to delete temp2.shp with


os.remove(filepath + "/temp2.shp") 

but I get the error WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'C:/Users/toke.nielsen/Desktop/temp/temp2.shp'



Is there a way to unlock temp2.shp after using runalg? And is there a way to clear all variables and memory when the plugin is done?


I have tried this, but it is not working with QGIS 2.2:


Releasing PyQGIS file locks?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...