增加健壮度。修复wda无法启动的bug。

This commit is contained in:
2025-09-19 14:30:39 +08:00
parent 5c9b6cd4c7
commit 08f76009b4
50 changed files with 65 additions and 25 deletions

View File

@@ -147,13 +147,15 @@ class Deviceinfo(object):
if new_udids:
futures = {self._connect_pool.submit(self._connect_device_task, udid): udid
for udid in new_udids}
for f in as_completed(futures, timeout=10):
udid = futures[f]
try:
f.result(timeout=8) # 单台 8 s 硬截止
except Exception as e:
LogManager.error(f"连接任务超时/失败: {e}", udid)
try:
for f in as_completed(futures, timeout=30):
udid = futures[f]
try:
f.result(timeout=8)
except Exception as e:
LogManager.error(text=f"连接任务失败:{e}", udid=udid)
except TimeoutError:
LogManager.warning(text="部分设备连接超时,已跳过")
time.sleep(1)
# ------------------------------------------------------------------
@@ -313,6 +315,12 @@ class Deviceinfo(object):
self._port_in_use.remove(port)
self._port_pool.append(port)
# 检测usb是否超时
def _usb_client_with_timeout(self,udid: str, timeout: 8):
with ThreadPoolExecutor(max_workers=1) as exe:
fut = exe.submit(wda.USBClient, udid, 8100)
return fut.result(timeout=timeout)
# ------------------------------------------------------------------
# 线程池里真正干活的地方(原 connectDevice 逻辑搬过来)
# ------------------------------------------------------------------
@@ -320,6 +328,12 @@ class Deviceinfo(object):
if not self.is_device_trusted(udid):
LogManager.warning("设备未信任,跳过 WDA 启动", udid)
return
d = self._usb_client_with_timeout(udid, 8) # 8 秒必返
if d is None:
LogManager.info(f"设备链接超时,{udid}")
return
try:
d = wda.USBClient(udid, 8100)
except Exception as e:

View File

@@ -36,11 +36,14 @@ if __name__ == "__main__":
manager.start()
# 设备监听(即使失败/很快返回,也不会导致主进程退出)
try:
info = Deviceinfo()
info.startDeviceListener()
except Exception as e:
print("[WARN] Device listener not running:", e)
# try:
# info = Deviceinfo()
# info.startDeviceListener()
# except Exception as e:
# print("[WARN] Device listener not running:", e)
info = Deviceinfo()
info.startDeviceListener()
# === 保活:阻塞主线程,直到收到 Ctrl+C/关闭 ===
import threading, time, signal