mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-12-16 00:56:26 +00:00
Update flask_server.py
This commit is contained in:
@@ -1641,6 +1641,7 @@ def get_detailed_gpu_info(gpu):
|
||||
output_lines = []
|
||||
start_time = time.time()
|
||||
timeout_seconds = 3.0
|
||||
json_objects_found = 0
|
||||
|
||||
while time.time() - start_time < timeout_seconds:
|
||||
if process.poll() is not None:
|
||||
@@ -1655,12 +1656,12 @@ def get_detailed_gpu_info(gpu):
|
||||
if len(output_lines) <= 10:
|
||||
print(f"[v0] Received line {len(output_lines)}: {line.strip()[:100]}")
|
||||
|
||||
# intel_gpu_top outputs individual JSON objects, not necessarily wrapped in array
|
||||
|
||||
# Find the first opening brace
|
||||
object_start = output.find('{')
|
||||
# Find all complete JSON objects
|
||||
search_start = 0
|
||||
while True:
|
||||
object_start = output.find('{', search_start)
|
||||
if object_start == -1:
|
||||
continue
|
||||
break
|
||||
|
||||
# Count braces to find complete object
|
||||
brace_count = 0
|
||||
@@ -1676,9 +1677,15 @@ def get_detailed_gpu_info(gpu):
|
||||
break
|
||||
|
||||
if object_end > object_start:
|
||||
# Extract the first complete JSON object
|
||||
json_objects_found += 1
|
||||
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]}")
|
||||
|
||||
try:
|
||||
@@ -1774,7 +1781,14 @@ def get_detailed_gpu_info(gpu):
|
||||
|
||||
except json.JSONDecodeError as 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:
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user