Skip to content

Commit

Permalink
add parallel_error funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
griembauer committed Dec 19, 2024
1 parent 7b1ae32 commit fde6c51
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/grass_gis_helpers/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@
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 as except in a try/except block around a parallel GRASS
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}")

Check failure on line 52 in src/grass_gis_helpers/parallel.py

View workflow job for this annotation

GitHub Actions / lint / ruff

Ruff (COM812)

src/grass_gis_helpers/parallel.py:52:72: COM812 Trailing comma missing
)


def run_module_parallel(
module,
module_kwargs,
Expand Down

0 comments on commit fde6c51

Please sign in to comment.