Hello dear grass users,
I’m writing python scripts and I wonder if is there a better way to handle tmp file between several mapcalc, For the moment I create a tmp raster file and once I don’t need anymore I remove with g.remove. If the script crash, the tmp raster still exists. If another script run and use the same tmp name, that could make conflict.
Is there a specific way the handle tmp raster (or vector) file ?
Thank you
Frank
On Sat, Jul 21, 2018 at 9:10 AM Micha Silver <tsvibar@gmail.com> wrote:
On 07/20/2018 06:05 PM, Frank David wrote:
Hello dear grass users,
I’m writing python scripts and I wonder if is there a better way to handle tmp file between several mapcalc, For the moment I create a tmp raster file and once I don’t need anymore I remove with g.remove. If the script crash, the tmp raster still exists. If another script run and use the same tmp name, that could make conflict.
Is there a specific way the handle tmp raster (or vector) file ?
I guess the proper way to deal with this is to first prepare a cleanup function. Then wrap your grass functions in a try…except structure, and whenever you catch an error, fire off the cleanup routine.
Use atexit package, see for example cleanup routine in r.sun.daily module:
https://trac.osgeo.org/grass/browser/grass-addons/grass7/raster/r.sun.daily/r.sun.daily.py#L612
and example on wiki:
https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#Sophisticated_cleanup_procedure
Anna
Thank you
Frank
_______________________________________________
grass-user mailing list
[grass-user@lists.osgeo.org](mailto:grass-user@lists.osgeo.org)
[https://lists.osgeo.org/mailman/listinfo/grass-user](https://lists.osgeo.org/mailman/listinfo/grass-user)
--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user