[GRASS-user] "Parallelization" of Python Script

Daniel Lee lee at isi-solutions.org
Tue Aug 7 01:49:27 PDT 2012


2012/8/7 Hamish <hamish_b at yahoo.com>

> Hamish wrote:
>

> for parallelizing an entire function in Python as you want, there's a
> method in grass7's i.landsat.rgb(.py) to look at that uses mp.Process.
> It's a bit more work since you have to manually ensure that the I/O pipes
> get closed.
>
> https://trac.osgeo.org/grass/browser/grass/trunk/scripts/i.landsat.rgb/i.landsat.rgb.py
>
> note the above script preserves the serial execution method intact (to
> make the imagery method easier to learn), so has ~ double the code than it
> actually needs.  But I think using the extra wrapper function makes the
> real guts of the imagery algorithm easier to read, understand, and
> maintain,
> and so keeping all the ugly parallelization stuff away is a good thing.
>

Another cool example. Although I would note that it's very possible to
embed the previous type of loop into methods or functions if you wish. I
normally write object-oriented though and have heard that the
multiprocessing library can only be used with functions because it has
trouble passing the objects (although maybe explicitly specifying self
would take care of that problem, I've never tried it). Does anybody have
experience there?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20120807/c39ca47e/attachment-0001.html>


More information about the grass-user mailing list