mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-21 04:00:04 +08:00
25 lines
512 B
Python
25 lines
512 B
Python
from __future__ import annotations
|
|||
|
|
|
||
|
|
import time
|
||
|
|
|
||
|
|
_OVERLOAD_UNTIL = 0.0
|
||
|
|
|
||
|
|
|
||
|
|
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()
|