临时提交
This commit is contained in:
@@ -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] = {}
|
||||
|
||||
Reference in New Issue
Block a user