Update flask_server.py

This commit is contained in:
MacRimi
2025-10-07 21:49:29 +02:00
parent 9632dd170a
commit b41b52df84

View File

@@ -1641,6 +1641,7 @@ def get_detailed_gpu_info(gpu):
output_lines = [] output_lines = []
start_time = time.time() start_time = time.time()
timeout_seconds = 3.0 timeout_seconds = 3.0
json_objects_found = 0
while time.time() - start_time < timeout_seconds: while time.time() - start_time < timeout_seconds:
if process.poll() is not None: if process.poll() is not None:
@@ -1655,12 +1656,12 @@ def get_detailed_gpu_info(gpu):
if len(output_lines) <= 10: if len(output_lines) <= 10:
print(f"[v0] Received line {len(output_lines)}: {line.strip()[:100]}") print(f"[v0] Received line {len(output_lines)}: {line.strip()[:100]}")
# intel_gpu_top outputs individual JSON objects, not necessarily wrapped in array # Find all complete JSON objects
search_start = 0
# Find the first opening brace while True:
object_start = output.find('{') object_start = output.find('{', search_start)
if object_start == -1: if object_start == -1:
continue break
# Count braces to find complete object # Count braces to find complete object
brace_count = 0 brace_count = 0
@@ -1676,9 +1677,15 @@ def get_detailed_gpu_info(gpu):
break break
if object_end > object_start: if object_end > object_start:
# Extract the first complete JSON object json_objects_found += 1
json_str = output[object_start:object_end] json_str = output[object_start:object_end]
print(f"[v0] Found complete JSON object ({len(json_str)} chars)")
if json_objects_found == 1:
print(f"[v0] Found first JSON object ({len(json_str)} chars) - skipping (baseline)")
search_start = object_end
continue
print(f"[v0] Found second JSON object ({len(json_str)} chars) - using this one")
print(f"[v0] JSON preview (first 300 chars): {json_str[:300]}") print(f"[v0] JSON preview (first 300 chars): {json_str[:300]}")
try: try:
@@ -1774,7 +1781,14 @@ def get_detailed_gpu_info(gpu):
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
print(f"[v0] JSON decode error: {e}") print(f"[v0] JSON decode error: {e}")
pass search_start = object_end
continue
else:
break
# If we found and parsed the second object, break out of the main loop
if json_objects_found >= 2 and data_retrieved:
break
else: else:
time.sleep(0.1) time.sleep(0.1)