修改全部停止,增加关注打招呼特殊翻译功能

This commit is contained in:
2025-11-04 14:07:46 +08:00
parent 1baf9c7fc5
commit f49755cb30
4 changed files with 91 additions and 63 deletions

View File

@@ -254,21 +254,53 @@ class ThreadManager:
}
return o
# @classmethod
# def batch_stop(cls, ids: List[str]) -> Tuple[int, str]:
# failed = []
# with ThreadPoolExecutor(max_workers=4) as executor:
# futures = {executor.submit(cls.stop, udid): udid for udid in ids}
# for future in as_completed(futures):
# udid = futures[future]
# try:
# code, msg = future.result()
# except Exception as e:
# LogManager.method_error(f"[{udid}] stop 调用异常: {e}", "task")
# failed.append(udid)
# continue
# if code != 200:
# failed.append(udid)
# if failed:
# return 207, f"部分任务停止失败: {failed}"
# return 200, "全部停止请求已提交"
@classmethod
def batch_stop(cls, ids: List[str]) -> Tuple[int, str]:
failed = []
results = []
with ThreadPoolExecutor(max_workers=4) as executor:
futures = {executor.submit(cls.stop, udid): udid for udid in ids}
for future in as_completed(futures):
udid = futures[future]
try:
code, msg = future.result()
results.append((udid, code, msg))
except Exception as e:
LogManager.method_error(f"[{udid}] stop 调用异常: {e}", "task")
failed.append(udid)
continue
if code != 200:
failed.append(udid)
# 等待所有线程完全停止
for udid, code, msg in results:
if code == 200:
obj = cls._tasks.get(udid)
if obj:
thread = obj["thread"]
while thread.is_alive():
time.sleep(0.1)
if failed:
return 207, f"部分任务停止失败: {failed}"
return 200, "全部停止请求已提交"
return 200, "全部任务已成功停止"