"""Общее состояние сессий, блокировка, лимиты и TTL.""" import threading TTL_SECONDS = 30 * 60 MAX_FILE_BYTES = 50 * 1024 * 1024 MAX_SESSION_BYTES = 500 * 1024 * 1024 _sessions: dict = {} _lock = threading.Lock() def _start_timer(sid: str) -> threading.Timer: """Запустить таймер автоочистки сессии через TTL.""" def _clean(): with _lock: _sessions.pop(sid, None) timer = threading.Timer(TTL_SECONDS, _clean) timer.daemon = True timer.start() return timer def configure(max_file_bytes: int = None, max_session_bytes: int = None, ttl_seconds: int = None): """Переопределить лимиты и TTL из конфигурации приложения.""" global MAX_FILE_BYTES, MAX_SESSION_BYTES, TTL_SECONDS if max_file_bytes is not None: MAX_FILE_BYTES = max_file_bytes if max_session_bytes is not None: MAX_SESSION_BYTES = max_session_bytes if ttl_seconds is not None: TTL_SECONDS = ttl_seconds