Files
iOSAI/Utils/ThreadManager.py

28 lines
799 B
Python
Raw Normal View History

2025-08-06 22:11:33 +08:00
from threading import Thread, Event
from Utils.LogManager import LogManager
from script.ScriptManager import ScriptManager
class ThreadManager():
threads = {}
@classmethod
def add(cls, udid, t: Thread, stopEvent: Event):
if udid in cls.threads:
print("▲ 线程已存在")
return
cls.threads[udid] = {"thread": t, "stopEvent": stopEvent}
@classmethod
def stop(cls, udid):
2025-08-07 21:37:46 +08:00
print(cls.threads)
2025-08-06 22:11:33 +08:00
info = cls.threads[udid]
if info:
info["stopEvent"].set() # 停止线程
info["thread"].join(timeout=3) # 等待线程退出
del cls.threads[udid]
2025-08-07 21:37:46 +08:00
LogManager.info("停止线程成功", udid)
2025-08-06 22:11:33 +08:00
else:
2025-08-07 21:37:46 +08:00
LogManager.info("无此线程,无需关闭", udid)