<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"Calibri\, sans-serif";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Segoe UI";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
span.MsoSmartlink
        {mso-style-priority:99;
        color:blue;
        background:#F3F2F1;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1778136171;
        mso-list-type:hybrid;
        mso-list-template-ids:510281876 201916433 201916441 201916443 201916431 201916441 201916443 201916431 201916441 201916443;}
@list l0:level1
        {mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-AU" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hello QGIS developers,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have a problem where I am calling a processing algorithm with Python not releasing file handles.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The smallest reproducible code sample and work flow does the following:
<o:p></o:p></p>
<ol style="margin-top:0cm" start="1" type="1">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1">Calls the native:rasterlayerzonalstatistics processing algorithm on a raster layer by adding it as a task through QgsApplication task manager<o:p></o:p></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1">The callback is invoked as expected, the statistics file is generated<o:p></o:p></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1">Remove the original layer in QGIS layers pane because you didn’t like it/you want to do it again for whatever reason.  It seems to be removed successfully.<o:p></o:p></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1">Now in file explorer, try to delete the layer file – get “file in use” error that won’t go away until  you close QGIS<o:p></o:p></li></ol>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I see on stackoverflow this is intermittently reported <a href="https://gis.stackexchange.com/questions/433300/deleting-folder-and-processed-files-in-qgis-using-pyqgis">
<span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;background:white;text-decoration:none">https://gis.stackexchange.com/questions/433300/deleting-folder-and-processed-files-in-qgis-using-pyqgis</span></a> and
<a href="https://gis.stackexchange.com/questions/243520/deleting-raster-file-after-doing-some-processing-in-qgis">
<span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;background:white;text-decoration:none">https://gis.stackexchange.com/questions/243520/deleting-raster-file-after-doing-some-processing-in-qgis</span></a> but have only seen workarounds.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The files for the QGIS workspace that reproduces the problem is uploaded here:
<a href="https://blightanner-my.sharepoint.com/:f:/g/personal/lauren_yang_blightanner_com_au/EvQ-xHtnXINFigK0FutFjngBxGKOlOB7M8pKVNYTAX4d5Q?e=sn9geF">
<span class="MsoSmartlink"><img border="0" width="16" height="16" style="width:.1666in;height:.1666in" id="Picture_x0020_7" src="cid:image007.png@01D937C4.34CDCAC0" alt="​Folder icon"> QGISProcessingFileHandles</span></a>  To reproduce the problem, in the python
 console of QGIS type exec(open('processFileSnippet.py').read())<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’m not sure if I’m not calling the processing algorithm correctly or not closing file handles when I should be.  If the link above doesn’t work, I can provide the python file snippet and supporting raster file.<o:p></o:p></p>
<p class="MsoNormal">Other details -  OS: Windows 10 64 bit, QGIS version 3.22.5, Python 3.9.5<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Any insight would be appreciated.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Lauren<o:p></o:p></p>
<p><b><span style="font-size:10.5pt;color:black">Lauren Yang</span></b><b><span style="font-size:8.0pt;color:black"><br>
</span></b><span style="font-size:10.5pt;color:#333333">Civil and Water Engineer</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:10.5pt;color:black"> </span><span style="color:black"><o:p></o:p></span></p>
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="110" valign="top" style="width:82.5pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal"><a href="https://blightanner.com.au/" title=""" "><span style="color:blue;text-decoration:none"><img border="0" width="105" height="47" style="width:1.0937in;height:.4895in" id="_x0030_.u7vhrswshg" src="cid:image001.jpg@01D937C2.FCC321D0"></span></a><o:p></o:p></p>
</td>
<td width="340" valign="top" style="width:255.0pt;padding:0cm 0cm 0cm 0cm">
<p class="MsoNormal" align="right" style="margin-top:2.0pt;text-align:right;line-height:11.0pt">
<span style="font-size:10.0pt">Brisbane +61 7 3251 8555</span><o:p></o:p></p>
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:10.0pt">Sydney +61 2 9170 3777</span><span style="font-family:"Calibri, sans-serif",serif"><o:p></o:p></span></p>
<p class="MsoNormal" align="right" style="text-align:right"><span style="font-size:10.0pt">Direct +61 7 3251 8555</span><o:p></o:p></p>
<p class="MsoNormal" align="right" style="text-align:right"><img border="0" width="36" height="41" style="width:.375in;height:.427in" id="_x0030_.dr2xptdil2l" src="cid:image002.png@01D937C2.FCC321D0"><a href="https://www.linkedin.com/company/1818291" title=""" "><span style="color:blue;text-decoration:none"><img border="0" width="36" height="36" style="width:.375in;height:.375in" id="_x0030_.ovoqdif045o" src="cid:image003.png@01D937C2.FCC321D0"></span></a><a href="https://www.instagram.com/blightanner/" title=""" "><span style="color:blue;text-decoration:none"><img border="0" width="36" height="36" style="width:.375in;height:.375in" id="_x0030_.28ppr8fljhk" src="cid:image004.png@01D937C2.FCC321D0"></span></a><a href="https://blightanner.com.au/" title=""" "><span style="color:blue;text-decoration:none"><img border="0" width="36" height="36" style="width:.375in;height:.375in" id="_x0030_.pj4xjbt9yf" src="cid:image005.png@01D937C2.FCC321D0"></span></a><o:p></o:p></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><a href="https://blightanner.com.au/news-article/tasmanian-cultural-hub-the-hedberg-wins-international-architecture-award/" title=""" "><span style="color:blue;text-decoration:none"><img border="0" width="450" height="179" style="width:4.6875in;height:1.8645in" id="_x0030_.mshbuji7v7t" src="cid:image006.png@01D937C2.FCC321D0" alt="nov Template1.png"></span></a><span style="color:black"><o:p></o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.5pt;color:black">ISO9001 Quality Approved JAS-ANZ</span></b><span style="color:black"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>