Deleting temporary files in a Python script

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Deleting temporary files in a Python script

Le Jeune Yann-2
Hello !

I would like to delete temporary files during the process of a python script. I have look at g.tempfile but it seems I don't know how to use it in a python script.
I have tried :
PROCESS_ID = os.getpid()
...
TEMP1 = grass.read_command ('g.tempfile',
    pid = PROCESS_ID)

But this changes nothing, after about 67200 calculations of r.viewshed no more temporary file can be created and the script stopped.

It seems to me that i miss something... If anyone knows how to solve that ?

Thanks for your help

yann

_______________________________________________
grass-user mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: Deleting temporary files in a Python script

Micha Silver-2

On 6/1/19 4:43 PM, Le Jeune Yann wrote:
Hello !

I would like to delete temporary files during the process of a python script. I have look at g.tempfile but it seems I don't know how to use it in a python script.
I have tried :
PROCESS_ID = os.getpid()
...
TEMP1 = grass.read_command ('g.tempfile',
    pid = PROCESS_ID)

But this changes nothing, after about 67200 calculations of r.viewshed no more temporary file can be created and the script stopped.


Are you manually removing the TEMP1 files within your script? I think that GRASS cleans up tempfiles only when the session exits, so with such a large number of calculations, you should manually remove them within the script.


It seems to me that i miss something... If anyone knows how to solve that ?

Thanks for your help

yann

_______________________________________________
grass-user mailing list
[hidden email]
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
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: Deleting temporary files in a Python script

Markus Neteler
On Sun, Jun 2, 2019 at 11:00 AM Micha Silver <[hidden email]> wrote:

> On 6/1/19 4:43 PM, Le Jeune Yann wrote:
>
> Hello !
>
> I would like to delete temporary files during the process of a python script. I have look at g.tempfile but it seems I don't know how to use it in a python script.
> I have tried :
> PROCESS_ID = os.getpid()
> ...
> TEMP1 = grass.read_command ('g.tempfile',
>     pid = PROCESS_ID)
>
> But this changes nothing, after about 67200 calculations of r.viewshed no more temporary file can be created and the script stopped.
>
>
> Are you manually removing the TEMP1 files within your script? I think that GRASS cleans up tempfiles only when the session exits, so with such a large number of calculations, you should manually remove them within the script.

For an example, see
scripts/r.in.aster/r.in.aster.py

therein, this function is used:
grass.try_remove(tempfile)

Markus
_______________________________________________
grass-user mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-user
Reply | Threaded
Open this post in threaded view
|

Re: Deleting temporary files in a Python script

Le Jeune Yann-2
Thanks to you both !
I think that's what i was missing...
It works now !

Regards,
yann

Le dim. 2 juin 2019 à 11:51, Markus Neteler <[hidden email]> a écrit :
On Sun, Jun 2, 2019 at 11:00 AM Micha Silver <[hidden email]> wrote:
> On 6/1/19 4:43 PM, Le Jeune Yann wrote:
>
> Hello !
>
> I would like to delete temporary files during the process of a python script. I have look at g.tempfile but it seems I don't know how to use it in a python script.
> I have tried :
> PROCESS_ID = os.getpid()
> ...
> TEMP1 = grass.read_command ('g.tempfile',
>     pid = PROCESS_ID)
>
> But this changes nothing, after about 67200 calculations of r.viewshed no more temporary file can be created and the script stopped.
>
>
> Are you manually removing the TEMP1 files within your script? I think that GRASS cleans up tempfiles only when the session exits, so with such a large number of calculations, you should manually remove them within the script.

For an example, see
scripts/r.in.aster/r.in.aster.py

therein, this function is used:
grass.try_remove(tempfile)

Markus


--

_______________________________________________
grass-user mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/grass-user