[GRASS-SVN] r52204 - grass/trunk/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 24 19:28:59 PDT 2012


Author: hamish
Date: 2012-06-24 19:28:58 -0700 (Sun, 24 Jun 2012)
New Revision: 52204

Modified:
   grass/trunk/lib/python/raster.py
Log:
fn to start r.mapcalc but not wait 'til it finishes (experimental)

Modified: grass/trunk/lib/python/raster.py
===================================================================
--- grass/trunk/lib/python/raster.py	2012-06-24 10:45:10 UTC (rev 52203)
+++ grass/trunk/lib/python/raster.py	2012-06-25 02:28:58 UTC (rev 52204)
@@ -99,3 +99,35 @@
                    verbose = verbose,
                    overwrite = overwrite) != 0:
 	fatal(_("An error occurred while running r.mapcalc"))
+
+
+def mapcalc_start(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
+    """!Interface to r.mapcalc, doesn't wait for it to finish, returns Popen object.
+
+    \code
+    >>> expr1 = '"%s" = "%s" * 10' % (output, input)
+    >>> p1 = grass.mapcalc_start(expr1, stdout = subprocess.PIPE)
+    >>> print p1
+    <subprocess.Popen object at 0xb7c12f6c>
+    >>> # start other jobs now ...
+    
+    >>> # collect the results and wait for them to finish:
+    >>> if not p1.stdout.closed:
+    ...     pout1 = p1.communicate()[0]
+    >>> p1.wait()
+    \endcode
+
+    (maybe stdout = subprocess.PIPE and p1.stdout.closed can be avoided)
+
+    @param exp expression
+    @param kwargs
+    
+    @return Popen object
+    """
+    t = string.Template(exp)
+    e = t.substitute(**kwargs)
+
+    return start_command('r.mapcalc', expression = e,
+                        quiet = quiet,
+                        verbose = verbose,
+                        overwrite = overwrite)



More information about the grass-commit mailing list