[GRASS-user] v.to.rast in a python loop, error

Hi,

I try to run v.to.rast of a line in a loop
to get a raster for each attribute of the vector (multiple columns).
Therefore I created a short python script, which is working
expept for that I am getting error messages:
ERROR: option <output>: <raster_attribute> exists.

Here I'd like to post the script which I tried on the North Carolina Dataset (streams vector) on GRASS 6.5SVN49268M (on Mac OSX with Python 2.6.6) with the same errors.

Can you also reproduce this? Maybe somebody knows what is causing this? Probably there is something wrong with my script as I am just in the beginning of writing python scripts... I am wondering as the command v.to.rast with the interactive menu works perfectly (no errors.)

Here the code:

#!/usr/bin/env python

import sys

import grass.script as grass
import grass.script.setup as gsetup

def main():

    for i in ['FULL_HYDRO','LENGTH']:

        grass.run_command("v.to.rast",
                    input = "streams@PERMANENT",
                    output = "rast_"+i,
                    type = "line",
                    use = "attr",
                    column = i)

    return 0

if __name__ == "__main__":
    sys.exit(main())

Best regards,
Johannes

--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://www.gmx.net/de/go/freephone/

On 8 February 2012 11:35, Johannes Radinger <JRadinger@gmx.at> wrote:

I try to run v.to.rast of a line in a loop
to get a raster for each attribute of the vector (multiple columns).
Therefore I created a short python script, which is working
expept for that I am getting error messages:
ERROR: option <output>: <raster_attribute> exists.

Here the code:

#!/usr/bin/env python

import sys

import grass.script as grass
import grass.script.setup as gsetup

def main():

for i in ['FULL_HYDRO','LENGTH']:

   grass\.run\_command\(&quot;v\.to\.rast&quot;,
               input = &quot;streams@PERMANENT&quot;,
               output = &quot;rast\_&quot;\+i,
               type = &quot;line&quot;,
               use = &quot;attr&quot;,
               column = i\)

return 0

if __name__ == "__main__":
sys.exit(main())

Have you tried adding flags = '-o' as an argument to
grass.run_command? That will overwrite the output raster if it already
exists.

Cheers,
Scott

Hi,

On 8 February 2012 11:35, Johannes Radinger <JRadinger@gmx.at> wrote:
> I try to run v.to.rast of a line in a loop
> to get a raster for each attribute of the vector (multiple columns).
> Therefore I created a short python script, which is working
> expept for that I am getting error messages:
> ERROR: option <output>: <raster_attribute> exists.
>
> Here the code:
>
> #!/usr/bin/env python
>
> import sys
>
> import grass.script as grass
> import grass.script.setup as gsetup
>
> def main():
>
> for i in ['FULL_HYDRO','LENGTH']:
>
> grass.run_command("v.to.rast",
> input = "streams@PERMANENT",
> output = "rast_"+i,
> type = "line",
> use = "attr",
> column = i)
>
> return 0
>
> if __name__ == "__main__":
> sys.exit(main())

Have you tried adding flags = '-o' as an argument to
grass.run_command? That will overwrite the output raster if it already
exists.

I haven't tried yet to use the overwrite option. It'll probably work. It is just that I am wondering why these rasters "exist" although all rasters are entirely removed from the mapset.

Can you reproduce this behaviour with that script and the North Carolina dataset?

Cheers,
Scott
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://www.gmx.net/de/go/freephone/

On 08/02/12 13:09, Johannes Radinger wrote:

Hi,

On 8 February 2012 11:35, Johannes Radinger<JRadinger@gmx.at> wrote:

I try to run v.to.rast of a line in a loop
to get a raster for each attribute of the vector (multiple columns).
Therefore I created a short python script, which is working
expept for that I am getting error messages:
ERROR: option<output>:<raster_attribute> exists.

Here the code:

#!/usr/bin/env python

import sys

import grass.script as grass
import grass.script.setup as gsetup

def main():

    for i in ['FULL_HYDRO','LENGTH']:

        grass.run_command("v.to.rast",
                    input = "streams@PERMANENT",
                    output = "rast_"+i,
                    type = "line",
                    use = "attr",
                    column = i)

    return 0

if __name__ == "__main__":
    sys.exit(main())

Have you tried adding flags = '-o' as an argument to
grass.run_command? That will overwrite the output raster if it already
exists.

I haven't tried yet to use the overwrite option. It'll probably work. It is just that I am wondering why these rasters "exist" although all rasters are entirely removed from the mapset.

Can you reproduce this behaviour with that script and the North Carolina dataset?

I tried in 6.4.2RC2 and in 6.5svn and it works like a charm. Obviously, if I try to run it a second time in the same mapset I get the output exists errors (i.e. I have to manually erase them).

Moritz

Scott Sinclair wrote:

Have you tried adding flags = '-o' as an argument to
grass.run_command? That will overwrite the output raster if it already
exists.

Actually, it will raise a ScriptError if you're running anything later
than 6.4.1. If you want to pass the --overwrite flag to the module,
you should pass overwrite=True to run_command() etc.

--
Glynn Clements <glynn@gclements.plus.com>

On 10 February 2012 03:22, <glynn@gclements.plus.com> wrote:

Scott Sinclair wrote:

Have you tried adding flags = '-o' as an argument to
grass.run_command? That will overwrite the output raster if it already
exists.

Actually, it will raise a ScriptError if you're running anything later
than 6.4.1. If you want to pass the --overwrite flag to the module,
you should pass overwrite=True to run_command() etc.

Thanks - I haven't used anything later than 6.4.1. Good to know.

Cheers,
Scott

Dear Glynn,
Dear Moritz,
Dear Scott,

> Have you tried adding flags = '-o' as an argument to
> grass.run_command? That will overwrite the output raster if it already
> exists.

Actually, it will raise a ScriptError if you're running anything later
than 6.4.1. If you want to pass the --overwrite flag to the module,
you should pass overwrite=True to run_command() etc.

so if I understand you correctly: This error is normal to GRASS6.5SVN?

It is really an interesting behavior. I remove the raster maps manually (with g.remove and f-flag) and cross check (g.list) so that the raster maps a really removed. Although the script gives this error...
However when I include g.remove in the script to remove them before v.to.rast everything works fine.
Interestingly when I include g.list before v.to.rast in the script (and all raster maps were removed before), g.list states that the maps are existing... So it seems that there is somehow a problem with the script/pyhton/GRASS interaction... although it works for Moritz Lennert.
Somehow it seems that v.to.rast has two passes (or more)...and the first one is performed even before g.list is processed in the script???

About my setup: GRASS6.5SVN (rev50782) on Mac OS X, Python 2.6.6...

and here the script with g.remove and g.list:

#!/usr/bin/env python

import sys

import grass.script as grass
import grass.script.setup as gsetup

def main():

    GRASS GIS.run_command("g.remove",
  # flags = "f",
     # rast = "rast_FULL_HYDRO,rast_LENGTH")

    grass.run_command("g.list",
          type = "rast")

    for i in ['FULL_HYDRO','LENGTH']:

        grass.run_command("v.to.rast",
                    input = "streams@PERMANENT",
                    output = "rast_"+i,
                    type = "line",
                    use = "attr",
                    column = i)

    return 0

if __name__ == "__main__":
    sys.exit(main())

And my output with although all maps were removed manually with g.remove and cross checked:

Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
(Mon Feb 13 11:12:27 2012)
/Users/Johannes Radinger/Desktop/test2.py
----------------------------------------------
raster files available in mapset <PERMANENT>:
basins elevation_shade lakes soils
elevation geology landuse
raster files available in mapset <user1>:
rast_FULL_HYDRO rast_LENGTH
----------------------------------------------
ERROR: option <output>: <rast_FULL_HYDRO> exists.
ERROR: option <output>: <rast_LENGTH> exists.
(Mon Feb 13 11:12:27 2012) Command finished (0 sec)

Of course I can use the overwrite-flag (overwrite=TRUE) to overcome the problem (or use g.remove in the script). I just wanted to know if that is a plattform specific problem, a problem with my script or just a bug in the GRASS-Python code...

Best regards
/johannes

--
Glynn Clements <glynn@gclements.plus.com>
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://www.gmx.net/de/go/freephone/

On 13/02/12 11:32, Johannes Radinger wrote:

And my output with although all maps were removed manually with g.remove and cross checked:

Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
(Mon Feb 13 11:12:27 2012)
/Users/Johannes Radinger/Desktop/test2.py
----------------------------------------------
raster files available in mapset<PERMANENT>:
basins elevation_shade lakes soils
elevation geology landuse
raster files available in mapset<user1>:
rast_FULL_HYDRO rast_LENGTH

   ^^^^^^^^^^^^^^^ ^^^^^^^^^^^

Both maps _do_ exist in mapset user1. So it is normal that the error appears.

Are you sure that you've been running g.remove in the same mapset as the script ?

Moritz

-------- Original-Nachricht --------

Datum: Mon, 13 Feb 2012 11:46:21 +0100
Von: Moritz Lennert <mlennert@club.worldonline.be>
An: Johannes Radinger <JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org, glynn@gclements.plus.com
Betreff: Re: [GRASS-user] v.to.rast in a python loop, error

On 13/02/12 11:32, Johannes Radinger wrote:
> And my output with although all maps were removed manually with g.remove
and cross checked:
>
> Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
> (Mon Feb 13 11:12:27 2012)
> /Users/Johannes Radinger/Desktop/test2.py
> ----------------------------------------------
> raster files available in mapset<PERMANENT>:
> basins elevation_shade lakes soils
> elevation geology landuse
> raster files available in mapset<user1>:
> rast_FULL_HYDRO rast_LENGTH
   ^^^^^^^^^^^^^^^ ^^^^^^^^^^^

Both maps _do_ exist in mapset user1. So it is normal that the error
appears.

That is the strange behavior I am describing: Although g.list is first in the script, v.to.rast is processed first (at least partly)...or something like that...

Are you sure that you've been running g.remove in the same mapset as the
script ?

Yes I am sure... That is the strange thing...I run g.remove (select all raster maps available for user1)...I can even run g.list manually before and there is no map... The maps are there as soon as I start the script (and then found by the g.list)

Johannes

Moritz
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://www.gmx.net/de/go/freephone/

On 13/02/12 12:26, Johannes Radinger wrote:

-------- Original-Nachricht --------

Datum: Mon, 13 Feb 2012 11:46:21 +0100 Von: Moritz
Lennert<mlennert@club.worldonline.be> An: Johannes
Radinger<JRadinger@gmx.at> CC: grass-user@lists.osgeo.org,
glynn@gclements.plus.com Betreff: Re: [GRASS-user] v.to.rast in a
python loop, error

On 13/02/12 11:32, Johannes Radinger wrote:

And my output with although all maps were removed manually with
g.remove

and cross checked:

Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
(Mon Feb 13 11:12:27 2012) /Users/Johannes
Radinger/Desktop/test2.py
---------------------------------------------- raster files
available in mapset<PERMANENT>: basins elevation_shade
lakes soils elevation geology landuse
raster files available in mapset<user1>: rast_FULL_HYDRO
rast_LENGTH

^^^^^^^^^^^^^^^ ^^^^^^^^^^^

Both maps _do_ exist in mapset user1. So it is normal that the
error appears.

That is the strange behavior I am describing: Although g.list is
first in the script, v.to.rast is processed first (at least
partly)...or something like that...

Sounds weird to me. You could try to suspend execution after each line using time.sleep(secs).

Note that in the last version of the script you posted the line with g.remove is commented out.

Yes I am sure... That is the strange thing...I run g.remove (select
all raster maps available for user1)...I can even run g.list manually
before and there is no map... The maps are there as soon as I start
the script (and then found by the g.list)

Nothing in your script creates these maps except for v.to.rast and its v.to.rast that complains about them existing...

Maybe by using several time.sleep() and g.list calls you can check exactly when this happens.

Moritz

-------- Original-Nachricht --------

Datum: Mon, 13 Feb 2012 13:18:58 +0100
Von: Moritz Lennert <mlennert@club.worldonline.be>
An: Johannes Radinger <JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org, glynn@gclements.plus.com
Betreff: Re: [GRASS-user] v.to.rast in a python loop, error

On 13/02/12 12:26, Johannes Radinger wrote:
>
>
> -------- Original-Nachricht --------
>> Datum: Mon, 13 Feb 2012 11:46:21 +0100 Von: Moritz
>> Lennert<mlennert@club.worldonline.be> An: Johannes
>> Radinger<JRadinger@gmx.at> CC: grass-user@lists.osgeo.org,
>> glynn@gclements.plus.com Betreff: Re: [GRASS-user] v.to.rast in a
>> python loop, error
>
>> On 13/02/12 11:32, Johannes Radinger wrote:
>>> And my output with although all maps were removed manually with
>>> g.remove
>> and cross checked:
>>>
>>> Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
>>> (Mon Feb 13 11:12:27 2012) /Users/Johannes
>>> Radinger/Desktop/test2.py
>>> ---------------------------------------------- raster files
>>> available in mapset<PERMANENT>: basins elevation_shade
>>> lakes soils elevation geology landuse
>>> raster files available in mapset<user1>: rast_FULL_HYDRO
>>> rast_LENGTH
>> ^^^^^^^^^^^^^^^ ^^^^^^^^^^^
>>
>> Both maps _do_ exist in mapset user1. So it is normal that the
>> error appears.
>
> That is the strange behavior I am describing: Although g.list is
> first in the script, v.to.rast is processed first (at least
> partly)...or something like that...

Sounds weird to me. You could try to suspend execution after each line
using time.sleep(secs).

Note that in the last version of the script you posted the line with
g.remove is commented out.

Hi again...

I know, g.remove was commented out. If not everything is working. My interpretation is: the new raster maps are created first (before anything else is performed) then g.remove removes these and thereafter v.to.rast is processed...

This is also supported when i try your suggestion (with time.sleep). Here what I run (and please look at the order of the output)? Is there anything running in parallel?

#!/usr/bin/env python

import sys
import time

import grass.script as grass
import grass.script.setup as gsetup

def main():

  print "start"
  sys.stdout.flush()

  grass.run_command("g.list",
          type = "rast")

  time.sleep(5)
  print "1st g.list over"
  sys.stdout.flush()

  grass.run_command("g.list",
          type = "rast")

  time.sleep(5)
  print "2nd g.list over"
  sys.stdout.flush()

  for i in ['FULL_HYDRO','LENGTH']:

    grass.run_command("v.to.rast",
          input = "streams@PERMANENT",
          output = "rast_"+i,
          type = "line",
          use = "attr",
          column = i)

  time.sleep(5)

  return 0

if __name__ == "__main__":
  sys.exit(main())

Output:

Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
(Mon Feb 13 15:08:07 2012)
/Users/Johannes Radinger/Desktop/test2.py
start
----------------------------------------------
raster files available in mapset <PERMANENT>:
basins elevation_shade lakes soils
elevation geology landuse
raster files available in mapset <user1>:
rast_FULL_HYDRO rast_LENGTH
----------------------------------------------
1st g.list over
----------------------------------------------
raster files available in mapset <PERMANENT>:
basins elevation_shade lakes soils
elevation geology landuse
raster files available in mapset <user1>:
rast_FULL_HYDRO rast_LENGTH
----------------------------------------------
ERROR: option <output>: <rast_FULL_HYDRO> exists.
ERROR: option <output>: <rast_LENGTH> exists.
2nd g.list over
(Mon Feb 13 15:08:23 2012) Command finished (15 sec)

Looks weird as "2nd g.list over" is printed after the ERROR, resp.
the ERROR is produced by v.to.rast before the print statement is processed...

I launch the script from within GRASS6.5SVN (Mac OSX) from File -> launch script.

/johannes

> Yes I am sure... That is the strange thing...I run g.remove (select
> all raster maps available for user1)...I can even run g.list manually
> before and there is no map... The maps are there as soon as I start
> the script (and then found by the g.list)

Nothing in your script creates these maps except for v.to.rast and its
v.to.rast that complains about them existing...

Maybe by using several time.sleep() and g.list calls you can check
exactly when this happens.

Moritz
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

--
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!
Jetzt informieren: http://www.gmx.net/de/go/freephone/

On 13/02/12 15:19, Johannes Radinger wrote:

-------- Original-Nachricht --------

Datum: Mon, 13 Feb 2012 13:18:58 +0100
Von: Moritz Lennert<mlennert@club.worldonline.be>
An: Johannes Radinger<JRadinger@gmx.at>
CC: grass-user@lists.osgeo.org, glynn@gclements.plus.com
Betreff: Re: [GRASS-user] v.to.rast in a python loop, error

On 13/02/12 12:26, Johannes Radinger wrote:

-------- Original-Nachricht --------

Datum: Mon, 13 Feb 2012 11:46:21 +0100 Von: Moritz
Lennert<mlennert@club.worldonline.be> An: Johannes
Radinger<JRadinger@gmx.at> CC: grass-user@lists.osgeo.org,
glynn@gclements.plus.com Betreff: Re: [GRASS-user] v.to.rast in a
python loop, error

On 13/02/12 11:32, Johannes Radinger wrote:

And my output with although all maps were removed manually with
g.remove

and cross checked:

Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
(Mon Feb 13 11:12:27 2012) /Users/Johannes
Radinger/Desktop/test2.py
---------------------------------------------- raster files
available in mapset<PERMANENT>: basins elevation_shade
lakes soils elevation geology landuse
raster files available in mapset<user1>: rast_FULL_HYDRO
rast_LENGTH

^^^^^^^^^^^^^^^ ^^^^^^^^^^^

Both maps _do_ exist in mapset user1. So it is normal that the
error appears.

That is the strange behavior I am describing: Although g.list is
first in the script, v.to.rast is processed first (at least
partly)...or something like that...

Sounds weird to me. You could try to suspend execution after each line
using time.sleep(secs).

Note that in the last version of the script you posted the line with
g.remove is commented out.

Hi again...

I know, g.remove was commented out. If not everything is working. My interpretation is: the new raster maps are created first (before anything else is performed) then g.remove removes these and thereafter v.to.rast is processed...

This is also supported when i try your suggestion (with time.sleep). Here what I run (and please look at the order of the output)? Is there anything running in parallel?

#!/usr/bin/env python

import sys
import time

import grass.script as grass
import grass.script.setup as gsetup

def main():

  print "start"
  sys.stdout.flush()

  grass.run_command("g.list",
          type = "rast")

  time.sleep(5)
  print "1st g.list over"
  sys.stdout.flush()

  grass.run_command("g.list",
          type = "rast")

  time.sleep(5)
  print "2nd g.list over"
  sys.stdout.flush()

  for i in ['FULL_HYDRO','LENGTH']:

    grass.run_command("v.to.rast",
          input = "streams@PERMANENT",
          output = "rast_"+i,
          type = "line",
          use = "attr",
          column = i)

  time.sleep(5)

  return 0

if __name__ == "__main__":
  sys.exit(main())

Output:

Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
(Mon Feb 13 15:08:07 2012)
/Users/Johannes Radinger/Desktop/test2.py
start
----------------------------------------------
raster files available in mapset<PERMANENT>:
basins elevation_shade lakes soils
elevation geology landuse
raster files available in mapset<user1>:
rast_FULL_HYDRO rast_LENGTH
----------------------------------------------
1st g.list over
----------------------------------------------
raster files available in mapset<PERMANENT>:
basins elevation_shade lakes soils
elevation geology landuse
raster files available in mapset<user1>:
rast_FULL_HYDRO rast_LENGTH
----------------------------------------------
ERROR: option<output>:<rast_FULL_HYDRO> exists.
ERROR: option<output>:<rast_LENGTH> exists.
2nd g.list over
(Mon Feb 13 15:08:23 2012) Command finished (15 sec)

Looks weird as "2nd g.list over" is printed after the ERROR, resp.
the ERROR is produced by v.to.rast before the print statement is processed...

I launch the script from within GRASS6.5SVN (Mac OSX) from File -> launch script.

Ok, I can reproduce your error using File->Launch script. No idea where that comes from, I'll try to look into it.

For the time being, just use g.remove or launch your script in the terminal.

Moritz

On 13/02/12 16:11, Moritz Lennert wrote:

On 13/02/12 15:19, Johannes Radinger wrote:

#!/usr/bin/env python

import sys
import time

import grass.script as grass
import grass.script.setup as gsetup

def main():

print "start"
sys.stdout.flush()

grass.run_command("g.list",
type = "rast")

time.sleep(5)
print "1st g.list over"
sys.stdout.flush()

grass.run_command("g.list",
type = "rast")

time.sleep(5)
print "2nd g.list over"
sys.stdout.flush()

for i in ['FULL_HYDRO','LENGTH']:

grass.run_command("v.to.rast",
input = "streams@PERMANENT",
output = "rast_"+i,
type = "line",
use = "attr",
column = i)

time.sleep(5)

return 0

if __name__ == "__main__":
sys.exit(main())

Output:

Launching script '/Users/Johannes Radinger/Desktop/test2.py'...
(Mon Feb 13 15:08:07 2012)
/Users/Johannes Radinger/Desktop/test2.py
start
----------------------------------------------
raster files available in mapset<PERMANENT>:
basins elevation_shade lakes soils
elevation geology landuse
raster files available in mapset<user1>:
rast_FULL_HYDRO rast_LENGTH
----------------------------------------------
1st g.list over
----------------------------------------------
raster files available in mapset<PERMANENT>:
basins elevation_shade lakes soils
elevation geology landuse
raster files available in mapset<user1>:
rast_FULL_HYDRO rast_LENGTH
----------------------------------------------
ERROR: option<output>:<rast_FULL_HYDRO> exists.
ERROR: option<output>:<rast_LENGTH> exists.
2nd g.list over
(Mon Feb 13 15:08:23 2012) Command finished (15 sec)

Looks weird as "2nd g.list over" is printed after the ERROR, resp.
the ERROR is produced by v.to.rast before the print statement is
processed...

I launch the script from within GRASS6.5SVN (Mac OSX) from File ->
launch script.

Ok, I can reproduce your error using File->Launch script. No idea where
that comes from, I'll try to look into it.

For the time being, just use g.remove or launch your script in the
terminal.

This is a bit over my head as I don't have a good view of how the GUI works (CC to Martin), but AFAICT the script is run through RunCmd on line 599 in gui/wxpython/gui_core/goutput.py [1].

So it quite definitely seems a wxgui problem, but I don't know how to go further with this. You should probably file a bug report.

Moritz

[1] http://trac.osgeo.org/grass/browser/grass/branches/develbranch_6/gui/wxpython/gui_core/goutput.py#L599

anyone know if python has a portable version of 'sync' from linux, and/or 'wait' from bash?

Hamish

Hamish wrote:

anyone know if python has a portable version of 'sync' from linux, and/or 'wait' from bash?

There is no reason to use 'sync' or an equivalent. sync causes
modified cache blocks to be written to the underlying block device. As
processes read from the cache (not the physical device), the only
observable effect of sync is upon timings (by getting pending I/O
operations out of the way, subsequent operations face less contention
for I/O bandwidth).

bash's "wait" command is only relevant if a process is being run in
the background.

run_command, write_command, read_command and parse_command all wait
for the process to finish. start_command, pipe_command, and
feed_command return a Popen object, on which you can call the .wait()
method to wait for termination (but you shouldn't do this until after
you have closed stdin and/or received EOF on stdout, otherwise it may
deadlock).

--
Glynn Clements <glynn@gclements.plus.com>

Johannes Radinger wrote:

Looks weird as "2nd g.list over" is printed after the ERROR, resp.
the ERROR is produced by v.to.rast before the print statement is processed...

This is almost certainly an artifact of the GUI.

Python's "print" statement writes to stdout by default, while GRASS
error messages are written to stderr. If both the print statment and
the v.to.rast commands are executed before the GUI gets around to
reading the pipes, the order in which the output appears will depend
upon the order in which the GUI reads the pipes.

This is a common problem with "splitting" stdout and stderr, and there
isn't a solution (other than to not split them, but then the GUI can't
distinguish between stdout and stderr).

Try executing the script from a terminal. Both stdout and stderr will
refer to the terminal, so the output will appear in the order in which
the statements are executed.

--
Glynn Clements <glynn@gclements.plus.com>