临时提交

This commit is contained in:
2025-11-03 14:27:31 +08:00
parent 8e8d676c79
commit 0ccd4ee97c
10 changed files with 22 additions and 3 deletions

View File

@@ -71,6 +71,17 @@ def _pick_free_port(low: int = 20000, high: int = 48000) -> int:
class DeviceInfo:
_instance = None
_instance_lock = threading.Lock()
def __new__(cls, *args, **kwargs):
# 双重检查锁,确保线程安全单例
if not cls._instance:
with cls._instance_lock:
if not cls._instance:
cls._instance = super().__new__(cls)
return cls._instance
# ---- 端口分配:加一个最小的“保留池”,避免并发选到同一个端口 ----
def _alloc_port(self) -> int:
with self._lock:
@@ -105,6 +116,10 @@ class DeviceInfo:
WDA_READY_TIMEOUT = float(os.getenv("WDA_READY_TIMEOUT", "35.0"))
def __init__(self) -> None:
# 防止多次初始化(因为 __init__ 每次调用 DeviceInfo() 都会执行)
if getattr(self, "_initialized", False):
return
self._lock = threading.RLock()
self._models: Dict[str, DeviceModel] = {}
self._iproxy: Dict[str, subprocess.Popen] = {}

View File

@@ -10,7 +10,6 @@ from pathlib import Path
from typing import Optional, Union, Dict, List
import psutil
from Utils.LogManager import LogManager
@@ -173,6 +172,11 @@ class FlaskSubprocessManager:
self.stop()
try:
self.start()
from Module.DeviceInfo import DeviceInfo
# 重新发送设备相关数据到flask
info = DeviceInfo()
for model in info._models.keys():
self.send(model)
except Exception as e:
LogManager.error(f"自动重启失败:{e}", udid="system")
time.sleep(2)

View File

@@ -50,7 +50,7 @@ if __name__ == "__main__":
# 清空日志
LogManager.clearLogs()
main(sys.argv)
# main(sys.argv)
# 添加iOS开发包到电脑上
deployer = DevDiskImageDeployer(verbose=True)

View File

@@ -26,7 +26,7 @@ def _force_utf8_everywhere():
except Exception:
pass
_force_utf8_everywhere()
# _force_utf8_everywhere()
class LogManager:
"""