kdoherty commited on
Commit
40bc35f
·
1 Parent(s): b1f40bc

Run mount probes in parallel to avoid proxy idle timeout

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import base64
2
  import socket
3
  import time
 
4
  from datetime import datetime, timezone
5
 
6
  import gradio as gr
@@ -76,19 +77,27 @@ def run_checks():
76
  "|---|-------|------|-----------:|-------------:|--------|",
77
  ]
78
 
79
- yield f"{header}\n\n⏳ Probing {len(MOUNTS)} mount points (~{READ_SECONDS}s each)…"
80
-
81
- rows = []
82
- for i, (mount_id, name) in enumerate(MOUNTS, 1):
83
- r = probe_mount(mount_id, USER, PASS)
84
- icon = ICON.get(r["status"], "?")
85
- rows.append(
86
- f"| {icon} | `{mount_id}` | {name} | {r['bytes']} | {r['rtcm']} | {r['detail']} |"
87
- )
88
- partial = "\n".join([header, "", *table_header, *rows])
89
- if i < len(MOUNTS):
90
- partial += f"\n\n⏳ {i}/{len(MOUNTS)} done, probing next…"
91
- yield partial
 
 
 
 
 
 
 
 
92
 
93
 
94
  DARK_THEME = gr.themes.Base(
 
1
  import base64
2
  import socket
3
  import time
4
+ from concurrent.futures import ThreadPoolExecutor, as_completed
5
  from datetime import datetime, timezone
6
 
7
  import gradio as gr
 
77
  "|---|-------|------|-----------:|-------------:|--------|",
78
  ]
79
 
80
+ yield f"{header}\n\n⏳ Probing {len(MOUNTS)} mount points in parallel (~{READ_SECONDS}s)…"
81
+
82
+ rows_by_idx: dict[int, str] = {}
83
+ with ThreadPoolExecutor(max_workers=len(MOUNTS)) as ex:
84
+ futures = {
85
+ ex.submit(probe_mount, mount_id, USER, PASS): (i, mount_id, name)
86
+ for i, (mount_id, name) in enumerate(MOUNTS)
87
+ }
88
+ for future in as_completed(futures):
89
+ i, mount_id, name = futures[future]
90
+ r = future.result()
91
+ icon = ICON.get(r["status"], "?")
92
+ rows_by_idx[i] = (
93
+ f"| {icon} | `{mount_id}` | {name} | "
94
+ f"{r['bytes']} | {r['rtcm']} | {r['detail']} |"
95
+ )
96
+ ordered = [rows_by_idx[j] for j in sorted(rows_by_idx)]
97
+ partial = "\n".join([header, "", *table_header, *ordered])
98
+ if len(rows_by_idx) < len(MOUNTS):
99
+ partial += f"\n\n⏳ {len(rows_by_idx)}/{len(MOUNTS)} done…"
100
+ yield partial
101
 
102
 
103
  DARK_THEME = gr.themes.Base(