[GRASS-dev] r.regression.multi failing
wenzeslaus at gmail.com
Wed Mar 23 09:14:30 PDT 2016
On Wed, Mar 23, 2016 at 11:57 AM, Markus Metz <markus.metz.giswork at gmail.com
> > Now this is treated as an error
> > (ERROR: Multiple regression failed"), which I guess is the equivalent of
> > grass.error() in a python script? Perhaps it would be possible to
> provide a
> > warning instead, and give an output that can be captured, like NA for the
> > coefficient estimates, instead of breaking of the function?
> Instead of grass.run_command(), you can use
> ps = grass.start_command()
> returncode = ps.wait()
> returncode is zero if the module finished successfully, non-zero if an
> error occurred, easy to capture in a script.
I don't know if the called module behavior is but or if it should be
improved somehow. Anyway, the way to deal with subprocess failure when
using GRASS Python API is to use try-except. You can also get run_command
to behave the same as in 6.4 version of the API using errors parameter:
returncode = run_command('g.region', ..., errors='status')
Other possible values are raise, ignore and exit. raise is the default and
it raises a CalledModuleError exception. Note that the exception is the
default because that's how the errors are handled in Python and it works
well also for read_command() which returns the module stdout by value.
There are different *_command() functions to conveniently cover different
cases. The most general is start_command() which is used similarly to the
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the grass-dev