mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 08:39:59 +08:00
* 性能优化 * 代码改进 * 优化浏览器代际切换逻辑 * 统一缓存与生命周期 * 添加aiomysql依赖 * 优化插件路径处理逻辑,简化条件判断;在虚拟环境包管理器中添加编码和错误处理参数以增强稳定性 * 🚨 auto fix by pre-commit hooks * 优化Windows下的关闭逻辑 * 代码优化 * bugfix:修复配置重载问题 * bugfix:修复插件加载启动竞态问题 * 收敛事件入口和权限上下文 * 优化 Windows launcher 关闭重启兜底 --------- Co-authored-by: HibiKier <775757368@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
36 lines
805 B
Python
36 lines
805 B
Python
from __future__ import annotations
|
|
|
|
import time
|
|
|
|
_OVERLOAD_UNTIL = 0.0
|
|
_LAST_ACTIVITY = time.monotonic()
|
|
|
|
|
|
def mark_activity() -> None:
|
|
"""Record lightweight runtime activity for idle-only maintenance jobs."""
|
|
global _LAST_ACTIVITY
|
|
_LAST_ACTIVITY = time.monotonic()
|
|
|
|
|
|
def idle_seconds() -> float:
|
|
return max(0.0, time.monotonic() - _LAST_ACTIVITY)
|
|
|
|
|
|
def signal_overload(duration: float = 5.0) -> None:
|
|
"""Mark the system as overloaded for a short time window."""
|
|
global _OVERLOAD_UNTIL
|
|
if duration <= 0:
|
|
return
|
|
now = time.monotonic()
|
|
until = now + duration
|
|
if until > _OVERLOAD_UNTIL:
|
|
_OVERLOAD_UNTIL = until
|
|
|
|
|
|
def is_overloaded() -> bool:
|
|
return time.monotonic() < _OVERLOAD_UNTIL
|
|
|
|
|
|
def should_pause_tasks() -> bool:
|
|
return is_overloaded()
|