继续优化批量停止脚本

This commit is contained in:
2025-09-20 20:07:16 +08:00
parent a4effb8058
commit 68b329f4f9
7 changed files with 122 additions and 39 deletions

View File

@@ -238,7 +238,9 @@ class ScriptManager():
session.double_tap(x, y)
print("--------------------------------------------")
event.wait(timeout=random.randint(300, 600))
# 换成
if not self.interruptible_sleep(event, random.randint(300, 600)):
break
session.swipe_up()
# 正常退出(外部 event 触发)
@@ -334,8 +336,8 @@ class ScriptManager():
if not anchor:
LogManager.method_info(f"数据库中的数据不足", "关注打招呼", udid)
event.wait(timeout=30)
continue
if not self.interruptible_sleep(event, 30):
continue
aid = anchor.get("anchorId", "")
anchorCountry = anchor.get("country", "")
@@ -554,7 +556,7 @@ class ScriptManager():
print("----------------------------------------------------------")
print("监控回复消息")
# 执行回复消息逻辑
self.monitorMessages(session, udid)
self.monitorMessages(session, udid, event)
homeButton = AiUtils.findHomeButton(udid)
if homeButton.exists:
@@ -901,3 +903,14 @@ class ScriptManager():
else:
LogManager.method_error(f"检测不到收件箱", "检测消息", udid)
raise Exception("当前页面找不到收件箱,重启")
# 放在 ScriptManager 类外面或 utils 里
def interruptible_sleep(self, event: threading.Event, seconds: float, slice_: float = 1.0):
"""把一次长 sleep 拆成 1 秒一片,随时响应 event"""
left = seconds
while left > 0 and not event.is_set():
timeout = min(slice_, left)
event.wait(timeout=timeout)
left -= timeout
return not event.is_set() # 返回 True 表示正常睡完False 被中断