From e39cde99db31b0b32ac1a064f12286eb19da1143 Mon Sep 17 00:00:00 2001 From: Anita Caron Date: Mon, 24 Jun 2024 12:59:06 +0100 Subject: [PATCH] Properly shutdown robot gateway after execution (#125) * properly shutdown robot gateway after execution use `finally` block for cleanup actions like shutting down the gateway. This ensures that the cleanup code runs regardless of whether an exception was raised. * enable `gateway.shutdown` to log exception in case of error Need to add the `raise_exception` parameter to the `gateway.shutdown` method to allow the caller to specify if an exception should be raised in case of error. The default value is `False`. --------- Co-authored-by: Anita Caron Co-authored-by: Anita Caron --- util/dashboard/dashboard.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/dashboard/dashboard.py b/util/dashboard/dashboard.py index d83d0d9..0c7777f 100755 --- a/util/dashboard/dashboard.py +++ b/util/dashboard/dashboard.py @@ -397,13 +397,13 @@ def run(): with open(dashboard_yml, 'w+') as f: yaml.dump(data_yml, f) - gateway.detach(robot_gateway) except Exception: logging.exception(f"Creating dashboard for {ontology_file} failed") - try: - gateway.close() - except Exception: - logging.exception("Closing JavaGateway failed") + finally: + try: + gateway.shutdown(raise_exception=True) + except Exception as e: + logging.exception("Failed to shut down the gateway: %s", e) sys.exit(0)