Skip to content

Commit

Permalink
Merge pull request #43 from mundialis/parallel_error
Browse files Browse the repository at this point in the history
Parallel: Add error/warning functions
  • Loading branch information
griembauer authored Dec 23, 2024
2 parents 2ccbafc + 1f085d5 commit 302987f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/grass_gis_helpers/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@
from .mapset import verify_mapsets


def check_parallel_errors(queue):
"""Check a parallel queue for errors in the worker modules by parsing
the stderr output for errors. A GRASS fatal will be thrown in this case.
To be used as except in a try/except block around a parallel GRASS
processing queue.
"""
for proc_num in range(queue.get_num_run_procs()):
proc = queue.get(proc_num)
if proc.returncode != 0:
# save all stderr to a variable and pass it to a GRASS
# exception
errmsg = proc.outputs["stderr"].value.strip()
grass.fatal(
_(f"\nERROR processing <{proc.get_bash()}>: {errmsg}"),
)


def check_parallel_warnings(queue):
"""Check a parallel queue for warnings in the worker modules by parsing
the stderr output for warnings. A GRASS warning will be issued in this case.
To be used after a successfully run processing queue.
"""
for mod in queue.get_finished_modules():
stderr = mod.outputs["stderr"].value.strip()
if "WARN" in stderr:
grass.warning(
_(f"\nWARNING processing <{mod.get_bash()}>: {stderr}"),
)


def run_module_parallel(
module,
module_kwargs,
Expand Down

0 comments on commit 302987f

Please sign in to comment.