I am using runalg (qgis:joinattributesbylocation) on two QgsVectorLayer objects. At the end of my script I'm trying to delete all the files created during the script. I can delete everything except the .shp and .dbf files from the two input vector layers for the process algorithm above. I remove all layers from the QgsMapRegistry before I try to delete the files. I've tried deleting all variables pointing to the layers, still doesn't work. The file lock remains until I exit QGIS. I tried the workaround posted here and it doesn't work for me, re-adding and removing the layers from the registry doesn't work. I also created new layers with the same files, added those to the registry, and then remove those, still no luck. The only way I can delete the files is to close QGIS.

  • does this answer help at all? It suggests you need to add layers to legend as well as registry for it to release the locks properly.
    – Steven Kay
    Commented Apr 17, 2016 at 12:27
  • Yes, I linked that post in my own post. Adding and removing the layers did not work, from his example it seemed he was saying that you cannot add the layer to the registry with the parameter addToLegend = FALSE, then remove it, and have it remove the lock. I added the layer normally with .addMapLayer, and that adds it to the legend by default I believe. Nevertheless, someone, maybe you, responded to my question and posted a link to a question where someone loaded their layers to memory and used the memory layers in the processing algorithms. I ended up going with that.
    – David M.
    Commented Apr 18, 2016 at 18:28
  • 2
    had the same issue. Resolved it by loading layers as iface.addVectorLayer() iso QgsVectorLayer().
    – cielke
    Commented Apr 24, 2017 at 12:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.