调整日志
This commit is contained in:
@@ -180,47 +180,58 @@ class Deviceinfo(object):
|
||||
self.manager.send(model.toDict())
|
||||
except Exception as e:
|
||||
LogManager.warning(f"{model.deviceId} 发送上线事件失败:{e}")
|
||||
LogManager.info(f"{model.deviceId} 设备上线,当前在线数:{len(self.deviceModelList)}")
|
||||
LogManager.method_info(f"{model.deviceId} 加入设备成功,当前在线数:{len(self.deviceModelList)}",method="device_count")
|
||||
|
||||
|
||||
# 删除设备
|
||||
def _remove_model(self, udid: str):
|
||||
print(f"【删】进入删除方法 udid={udid}")
|
||||
LogManager.method_info(f"【删】进入删除方法 udid={udid}", method="device_count")
|
||||
# 1. 纯内存临界区——毫秒级
|
||||
with self._lock:
|
||||
print(f"【删】拿到锁 udid={udid}")
|
||||
LogManager.method_info(f"【删】拿到锁 udid={udid}",
|
||||
method="device_count")
|
||||
model = self._model_index.pop(udid, None)
|
||||
if not model:
|
||||
print(f"【删】模型已空,直接返回 udid={udid}")
|
||||
LogManager.method_info(f"【删】模型已空,直接返回 udid={udid}",method="device_count")
|
||||
return
|
||||
if model.deleting:
|
||||
print(f"【删】正在删除中,幂等返回 udid={udid}")
|
||||
LogManager.method_info(method="device_count", text=f"【删】正在删除中,幂等返回 udid={udid}")
|
||||
return
|
||||
model.deleting = True
|
||||
# 标记维删除设备
|
||||
model.type = 2
|
||||
print(f"【删】标记 deleting=True udid={udid}")
|
||||
|
||||
LogManager.method_info("【删】标记 deleting=True udid={udid}","device_count")
|
||||
# 过滤列表
|
||||
before = len(self.deviceModelList)
|
||||
self.deviceModelList = [m for m in self.deviceModelList if m.deviceId != udid]
|
||||
after = len(self.deviceModelList)
|
||||
print(f"【删】列表过滤 before={before} → after={after} udid={udid}")
|
||||
LogManager.method_info(f"【删】列表过滤 before={before} → after={after} udid={udid}","device_count")
|
||||
|
||||
# 端口
|
||||
self._port_in_use.discard(model.screenPort)
|
||||
self._port_pool.append(model.screenPort)
|
||||
print(f"【删】回收端口 port={model.screenPort} udid={udid}")
|
||||
LogManager.method_info(f"【删】回收端口 port={model.screenPort} udid={udid}", method="device_count")
|
||||
|
||||
# 进程
|
||||
to_kill = [item for item in self.pidList if item.get("id") == udid]
|
||||
self.pidList = [item for item in self.pidList if item.get("id") != udid]
|
||||
print(f"【删】待杀进程数 count={len(to_kill)} udid={udid}")
|
||||
LogManager.method_info(f"【删】待杀进程数 count={len(to_kill)} udid={udid}", method="device_count")
|
||||
|
||||
# 2. IO 区无锁
|
||||
for idx, item in enumerate(to_kill, 1):
|
||||
print(f"【删】杀进程 {idx}/{len(to_kill)} pid={item.get('target').pid} udid={udid}")
|
||||
LogManager.method_error(f"【删】杀进程 {idx}/{len(to_kill)} pid={item.get('target').pid} udid={udid}", method="device_count")
|
||||
self._terminate_proc(item.get("target"))
|
||||
print(f"【删】进程清理完成 udid={udid}")
|
||||
LogManager.method_info(f"【删】进程清理完成 udid={udid}", method="device_count")
|
||||
|
||||
# 3. 网络 IO
|
||||
retry = 3
|
||||
@@ -228,18 +239,21 @@ class Deviceinfo(object):
|
||||
try:
|
||||
self.manager.send(model.toDict())
|
||||
print(f"【删】下线事件已发送 udid={udid}")
|
||||
LogManager.method_info(f"【删】下线事件已发送 udid={udid}", method="device_count")
|
||||
break
|
||||
except Exception as e:
|
||||
retry -= 1
|
||||
print(f"【删】发送事件失败 retry={retry} err={e} udid={udid}")
|
||||
LogManager.method_error(f"【删】发送事件失败 retry={retry} err={e} udid={udid}", method="device_count")
|
||||
time.sleep(0.2)
|
||||
else:
|
||||
print(f"【删】发送事件彻底失败,主动退出 udid={udid}")
|
||||
os._exit(1)
|
||||
LogManager.method_error(f"【删】发送事件彻底失败,主动退出 udid={udid}", method="device_count")
|
||||
|
||||
print(f"【删】===== 设备 {udid} 删除全流程结束 =====")
|
||||
LogManager.method_info(f"【删】===== 设备 {udid} 删除全流程结束 =====", method="device_count")
|
||||
print(len(self.deviceModelList))
|
||||
|
||||
LogManager.method_info(f"当前剩余设备数量:{len(self.deviceModelList)}", method="device_count")
|
||||
|
||||
# region ===================== 端口分配与回收 =====================
|
||||
def _alloc_port(self) -> int:
|
||||
@@ -295,8 +309,6 @@ class Deviceinfo(object):
|
||||
if target:
|
||||
self.pidList.append({"target": target, "id": udid})
|
||||
|
||||
# endregion
|
||||
|
||||
# region ===================== 工具方法 =====================
|
||||
def is_device_trusted(self, udid: str) -> bool:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user