[QGIS-Developer] Pygis: Processing algorithms not releasing file handles

Lauren Yang lauren.yang at blightanner.com.au
Thu Feb 2 17:48:22 PST 2023


Hello QGIS developers,

I have a problem where I am calling a processing algorithm with Python not releasing file handles.

The smallest reproducible code sample and work flow does the following:

  1.  Calls the native:rasterlayerzonalstatistics processing algorithm on a raster layer by adding it as a task through QgsApplication task manager
  2.  The callback is invoked as expected, the statistics file is generated
  3.  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.
  4.  Now in file explorer, try to delete the layer file - get "file in use" error that won't go away until  you close QGIS

I see on stackoverflow this is intermittently reported https://gis.stackexchange.com/questions/433300/deleting-folder-and-processed-files-in-qgis-using-pyqgis and https://gis.stackexchange.com/questions/243520/deleting-raster-file-after-doing-some-processing-in-qgis but have only seen workarounds.

The files for the QGIS workspace that reproduces the problem is uploaded here: [?Folder icon]  QGISProcessingFileHandles<https://blightanner-my.sharepoint.com/:f:/g/personal/lauren_yang_blightanner_com_au/EvQ-xHtnXINFigK0FutFjngBxGKOlOB7M8pKVNYTAX4d5Q?e=sn9geF>  To reproduce the problem, in the python console of QGIS type exec(open('processFileSnippet.py').read())

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.
Other details -  OS: Windows 10 64 bit, QGIS version 3.22.5, Python 3.9.5

Any insight would be appreciated.

Thanks,
Lauren

Lauren Yang
Civil and Water Engineer

[cid:image001.jpg at 01D937C2.FCC321D0]<https://blightanner.com.au/>
Brisbane +61 7 3251 8555
Sydney +61 2 9170 3777
Direct +61 7 3251 8555
[cid:image002.png at 01D937C2.FCC321D0][cid:image003.png at 01D937C2.FCC321D0]<https://www.linkedin.com/company/1818291>[cid:image004.png at 01D937C2.FCC321D0]<https://www.instagram.com/blightanner/>[cid:image005.png at 01D937C2.FCC321D0]<https://blightanner.com.au/>
[nov Template1.png]<https://blightanner.com.au/news-article/tasmanian-cultural-hub-the-hedberg-wins-international-architecture-award/>
ISO9001 Quality Approved JAS-ANZ

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230203/c4d70511/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 7674 bytes
Desc: image001.jpg
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230203/c4d70511/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.png
Type: image/png
Size: 146 bytes
Desc: image002.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230203/c4d70511/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image003.png
Type: image/png
Size: 2843 bytes
Desc: image003.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230203/c4d70511/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image004.png
Type: image/png
Size: 3494 bytes
Desc: image004.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230203/c4d70511/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image005.png
Type: image/png
Size: 1570 bytes
Desc: image005.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230203/c4d70511/attachment-0009.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image006.png
Type: image/png
Size: 114460 bytes
Desc: image006.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230203/c4d70511/attachment-0010.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image007.png
Type: image/png
Size: 210 bytes
Desc: image007.png
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230203/c4d70511/attachment-0011.png>


More information about the QGIS-Developer mailing list