<div>Hello! </div><br><div>I am working on a plugin that uses a temporary folder to load layer filers on that can end up having the same name so it is needed to have qgis closing the files to allow deleting them. I tested this on qgis 3.8.3 and for linux it worked fine but on windows still gives "error 32 , cannot remove because the file is in use".</div><br><br><code><pre style="background-color:rgba(0,0,0,0.05);padding:0.2em 1em"><div><span style="color:rgb(169, 183, 198)"><font style="font-family:"DejaVu Sans Mono"">process(l)</font></span></div><div><span style="color:rgb(169, 183, 198)"><font style="font-family:"DejaVu Sans Mono"">l.commitChanges()</font></span></div><div><span style="color:rgb(169, 183, 198)"><font style="font-family:"DejaVu Sans Mono"">l.endEditCommand()</font></span></div><div><span style="color:rgb(169, 183, 198)"><font style="font-family:"DejaVu Sans Mono"">QgsProject.instance().removeMapLayer(l.id())</font></span></div><div><span style="color:rgb(169, 183, 198)"><font style="font-family:"DejaVu Sans Mono"">path=l.dataProvider().dataSourceUri().split("|layername=")[0]</font></span></div><div><span style="color:rgb(169, 183, 198)"><font style="font-family:"DejaVu Sans Mono"">Path(path).unlink()  #remove file returns file being used error on this line</font></span></div><br></pre></code><img class="mailspring-open" alt="Sent from Mailspring" width="0" height="0" style="border:0; width:0; height:0;" src="https://link.getmailspring.com/open/4DE5931E-4D01-429E-B07A-612395DDECA7@getmailspring.com?me=d0cf9b4a&recipient=cWdpcy1kZXZlbG9wZXJAbGlzdHMub3NnZW8ub3Jn">