[GRASS-user] region issues using python multiprocessing.Pool()

Pietro Zambelli peter.zamb at gmail.com
Wed Jul 10 15:48:05 PDT 2013


Hi Eric,

On Wednesday 10 Jul 2013 15:48:04 Eric Goddard wrote:
> If I run the script without multiprocessing enabled the script
> executes properly; If I run it with multiprocessing enabled, The
> script executes successfully but the  pixel range is 0-0; I think this
> is caused by the region settings. Can the use_temp_region() function
> be used as it is below to execute multiple mapcalc jobs in parallel
> that have different extents? Once I have this working I'd like to make
> a more generic tool a-la the i.landsat/toar tools.

I did something similar to run raster modules splitting the region in several 
tiles for grass7.

I don't think that the function use_temp_region, can solve your problem, If 
you look at the code [0], the function set the environmental variable, 
therefore in a multiprocessing environment you have several process that set 
the same variable at the same time...

Therefore I don't think that could work...

But you can isolate the GRASS command giving a dictionary with the 
environmental variables... something like:

{{{
import os

myenv = os.environ.copy()
# now change the variables in the dictionary
myenv['GISRC'] = 'mygisrc'  # etc.
run_command('r.something', bla, bla, env=myenv)
}}}

in this way the process will use as environmental variables the dictionary 
myenv, therefore each process will be isolated from the other...

I've implemented for grass7, you may see the code here:

http://trac.osgeo.org/grass/browser/grass/trunk/lib/python/pygrass/modules/grid/grid.py#L34


All the best.

Pietro

[0]  
http://trac.osgeo.org/grass/browser/grass/trunk/lib/python/script/core.py#L909



More information about the grass-user mailing list