Skip to content

Commit

Permalink
feat(subprocess): add check of return code
Browse files Browse the repository at this point in the history
  • Loading branch information
jmkerloch authored and azarz committed Mar 21, 2024
1 parent 7b3c138 commit c1fffea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

CHANGED:
- Valhalla build config: increase default isochrone limits
- subprocess : check return code and raise Runtime exception if not 0

## 2.2.4

Expand Down
9 changes: 8 additions & 1 deletion r2gg/_subprocess_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def subprocess_execution(args, logger, outfile = None):
"""
try:
str_args = [str(arg) for arg in args]
logger.info('Subprocess: \"' + " ".join(str_args) + '\"')
subprocess_arg = " ".join(str_args)
logger.info('Subprocess: \"' + subprocess_arg + '\"')
if outfile is not None:
with open(outfile, "w") as out:
process = subprocess.Popen(
Expand All @@ -32,6 +33,12 @@ def subprocess_execution(args, logger, outfile = None):
process_output, _ = process.communicate()
logger.info(process_output.decode("utf-8"))

returncode = process.returncode
if process.returncode != 0:
error_msg = f"Invalid returncode {returncode} for subprocess '{subprocess_arg}'"
logger.error(error_msg)
raise RuntimeError(error_msg)


except (OSError, subprocess.CalledProcessError) as exception:
logger.info('Exception occured: ' + str(exception))
Expand Down

0 comments on commit c1fffea

Please sign in to comment.