[GRASS-dev] grass.mapcalc() python wrapper using grass.start_command()

Hamish hamish_b at yahoo.com
Sun Jun 24 23:34:43 PDT 2012


Hamish wrote:
> in making some of the python modules multithreaded, it would
> be useful to have a version of grass.mapcalc() which didn't
> wait until it was done, and returned the Popen object instead.
> 
> e.g. to process three r,g,b bands in parallel.
> 
> I just added an experimental grass.mapcalc_start() fn to
> trunk/lib/python/raster.py,

an example for running 3 r.mapcalcs in parallel:

before:
  grass.mapcalc('%s.red = r#%s' % (out, in_R))
  grass.mapcalc('%s.grn = g#%s' % (out, in_G))
  grass.mapcalc('%s.blu = b#%s' % (out, in_B))

after:
  pr = grass.mapcalc_start('%s.red = r#%s' % (out, in_R))
  pg = grass.mapcalc_start('%s.grn = g#%s' % (out, in_G))
  pb = grass.mapcalc_start('%s.blu = b#%s' % (out, in_B))
  pr.wait()
  pg.wait()
  pb.wait()


since the parent process retains control of the pipes by default,
AFAIK p.communicate() is not needed here, errors and messages
just get propagated to the terminal as they occur.


Hamish


More information about the grass-dev mailing list