From b8b212f761bb956b738d55eb33628f4df6570ff7 Mon Sep 17 00:00:00 2001 From: ljcornel Date: Mon, 27 Mar 2023 10:00:35 +0200 Subject: [PATCH] Add error handling for OVMS connections --- geti_sdk/deployment/deployed_model.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/geti_sdk/deployment/deployed_model.py b/geti_sdk/deployment/deployed_model.py index eac359f3..e1fed50d 100644 --- a/geti_sdk/deployment/deployed_model.py +++ b/geti_sdk/deployment/deployed_model.py @@ -20,6 +20,7 @@ import shutil import sys import tempfile +import time import zipfile from typing import Any, Dict, List, Optional, Tuple, Union @@ -49,6 +50,8 @@ LABEL_GROUPS_KEY = "label_groups" ALL_LABELS_KEY = "all_labels" +OVMS_TIMEOUT = 10 # Max time to wait for OVMS models to become available + @attr.define class DeployedModel(OptimizedModel): @@ -229,7 +232,16 @@ def load_inference_model( model_address = generate_ovms_model_address( ovms_address=device, model_name=model_name ) - model_adapter = OVMSAdapter(model_address) + + ovms_connected = False + t_start = time.time() + while not ovms_connected and time.time() - t_start < OVMS_TIMEOUT: + # If OVMS has just started, model needs some time to initialize + try: + model_adapter = OVMSAdapter(model_address) + ovms_connected = True + except RuntimeError: + time.sleep(0.5) # Load model configuration config_path = os.path.join(self._model_data_path, "config.json")