This commit is contained in:
2025-11-30 09:15:08 +08:00
parent bef82d41c8
commit 52597178a8
2 changed files with 17 additions and 4 deletions

View File

@@ -675,6 +675,19 @@ def is_forbidden_time() -> bool:
end = now.replace(hour=20, minute=0, second=0, microsecond=0)
return start <= now < end
def wait_until_out_of_forbidden(interval_sec: float = 5.0, stop_event: threading.Event | None = None) -> None:
"""
在禁跑时段内循环等待,直到禁跑时段结束
参数:
interval_sec: 轮询间隔秒数
stop_event: 可选停止事件,若设置则在等待期间可提前结束
"""
while is_forbidden_time():
if stop_event is not None and stop_event.wait(timeout=interval_sec):
break
time.sleep(interval_sec)
def seconds_until(hour: int, minute: int) -> float:
"""
@@ -782,9 +795,8 @@ def main():
if stop_event.wait(timeout=300):
continue
cleanup_all_browsers()
secs = seconds_until(20, 0)
logger.info(f"处于禁跑时段休眠至20:00剩余 {int(secs)}")
time.sleep(secs)
logger.info("处于禁跑时段,等待至禁跑结束")
wait_until_out_of_forbidden()
continue
executor = ThreadPoolExecutor(max_workers=len(proxies))
@@ -815,6 +827,7 @@ def main():
pass
time.sleep(300)
cleanup_all_browsers()
wait_until_out_of_forbidden()
break
for f, proxy in list(futures_map.items()):
if f.done() and not stop_event.is_set() and not restart_event.is_set():