[GRASS-dev] Python scripts: trigger cleanup function at keyboard interrupt (CTRL-C)

Moritz Lennert mlennert at club.worldonline.be
Mon Oct 14 08:04:48 PDT 2019


On 14/10/19 16:44, Anna Petrášová wrote:
> This is used in many scripts and should work:
> https://grasswiki.osgeo.org/wiki/GRASS_Python_Scripting_Library#Sophisticated_cleanup_procedure

Not sure this works on a Ctrl-C. ISTR it doesn't, but this would have to 
be verified.

Moritz

> 
> On Mon, Oct 14, 2019 at 10:00 AM Markus Neteler <neteler at osgeo.org 
> <mailto:neteler at osgeo.org>> wrote:
> 
>     Hi,
> 
>     in the GRASS GIS 6 shell scripts we used this code to clean up temp
>     files upon CTRL-C signal:
> 
>     cleanup()
>     {
>         g.message -v "Cleaning up ..."
>         cd "$MSET_DIR"
>         rm -rf "$TMP_DIR"
>     }
>     #### trap ctrl-c so that we can clean up tmp
>     trap 'cleanup' 2 3 15
> 
>     If there anything similar we could add to the python scripts?
> 
>     thanks
>     Markus
>     _______________________________________________
>     grass-dev mailing list
>     grass-dev at lists.osgeo.org <mailto:grass-dev at lists.osgeo.org>
>     https://lists.osgeo.org/mailman/listinfo/grass-dev
> 
> 
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-dev
> 




More information about the grass-dev mailing list