|
@@ -1241,25 +1241,24 @@ class MainWindow(QMainWindow):
|
|
|
ips = self._collect_camera_ips()
|
|
ips = self._collect_camera_ips()
|
|
|
if not ips:
|
|
if not ips:
|
|
|
return
|
|
return
|
|
|
- results = {}
|
|
|
|
|
- for ip in ips:
|
|
|
|
|
|
|
+
|
|
|
|
|
+ def ping_one(ip: str) -> tuple:
|
|
|
try:
|
|
try:
|
|
|
if sys.platform == "win32":
|
|
if sys.platform == "win32":
|
|
|
r = subprocess.run(["ping", "-n", "1", ip], capture_output=True, timeout=5, text=True, creationflags=subprocess.CREATE_NO_WINDOW)
|
|
r = subprocess.run(["ping", "-n", "1", ip], capture_output=True, timeout=5, text=True, creationflags=subprocess.CREATE_NO_WINDOW)
|
|
|
else:
|
|
else:
|
|
|
r = subprocess.run(["ping", "-c", "1", ip], capture_output=True, timeout=5, text=True)
|
|
r = subprocess.run(["ping", "-c", "1", ip], capture_output=True, timeout=5, text=True)
|
|
|
if r.returncode != 0:
|
|
if r.returncode != 0:
|
|
|
- results[ip] = -1
|
|
|
|
|
- else:
|
|
|
|
|
- m = re.search(r'time[=<]\s*(\d+(?:\.\d+)?)\s*ms', r.stdout, re.IGNORECASE)
|
|
|
|
|
- if m:
|
|
|
|
|
- results[ip] = float(m.group(1))
|
|
|
|
|
- else:
|
|
|
|
|
- results[ip] = 0
|
|
|
|
|
|
|
+ return (ip, -1)
|
|
|
|
|
+ m = re.search(r'time[=<]\s*(\d+(?:\.\d+)?)\s*ms', r.stdout, re.IGNORECASE)
|
|
|
|
|
+ return (ip, float(m.group(1)) if m else 0)
|
|
|
except subprocess.TimeoutExpired:
|
|
except subprocess.TimeoutExpired:
|
|
|
- results[ip] = -1
|
|
|
|
|
|
|
+ return (ip, -1)
|
|
|
except Exception:
|
|
except Exception:
|
|
|
- results[ip] = -1
|
|
|
|
|
|
|
+ return (ip, -1)
|
|
|
|
|
+
|
|
|
|
|
+ with ThreadPoolExecutor(max_workers=len(ips)) as pool:
|
|
|
|
|
+ results = dict(pool.map(ping_one, ips))
|
|
|
self.camera_signal_signal.emit(results)
|
|
self.camera_signal_signal.emit(results)
|
|
|
|
|
|
|
|
def _on_camera_signal(self, results: dict):
|
|
def _on_camera_signal(self, results: dict):
|