From ad86d5e2b4620629b9a0bff76d5bd86716e25168 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Mon, 21 Oct 2024 15:53:39 -0600 Subject: [PATCH] Handle invalid intel json --- frigate/util/services.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/frigate/util/services.py b/frigate/util/services.py index 3f8ecf32c..7ff46f039 100644 --- a/frigate/util/services.py +++ b/frigate/util/services.py @@ -279,10 +279,27 @@ def get_intel_gpu_stats() -> dict[str, str]: logger.error(f"Unable to poll intel GPU stats: {p.stderr}") return None else: + output = "".join(p.stdout.split()) + try: - data = json.loads(f'[{"".join(p.stdout.split())}]') + data = json.loads(f"[{output}]") except json.JSONDecodeError: - return {"gpu": "-%", "mem": "-%"} + data = None + + # json is incomplete, remove characters until we get to valid json + while True: + while output and output[-1] != "}": + output = output[:-1] + + if not output: + return {"gpu": "", "mem": ""} + + try: + data = json.loads(f"[{output}]") + break + except json.JSONDecodeError: + output = output[:-1] + continue results: dict[str, str] = {} render = {"global": []}