[GRASS-user] tmp file

Anna Petrášová kratochanna at gmail.com
Sat Jul 21 10:26:34 PDT 2018


On Sat, Jul 21, 2018 at 9:10 AM Micha Silver <tsvibar at 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 listgrass-user at lists.osgeo.orghttps://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 at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20180721/62731d50/attachment.html>


More information about the grass-user mailing list