UnisKB/apps/maxkb/settings/mem.py

20 lines
540 B
Python
Raw Normal View History

2025-11-04 01:31:27 +00:00
# coding=utf-8
import os
import gc
import threading
from maxkb.const import CONFIG
from common.utils.logger import maxkb_logger
2025-11-04 03:20:29 +00:00
import random
2025-11-04 01:31:27 +00:00
CURRENT_PID=os.getpid()
# 1 hour
GC_INTERVAL = 3600
def force_gc():
collected = gc.collect()
maxkb_logger.debug(f"(PID: {CURRENT_PID}) Forced GC ({collected} objects collected)")
2025-11-04 03:20:29 +00:00
threading.Timer(GC_INTERVAL - random.randint(0, 900, force_gc).start()
2025-11-04 01:31:27 +00:00
2025-11-04 03:03:56 +00:00
if CONFIG.get("ENABLE_MEMORY_OPTIMIZATION", '1') == "1":
2025-11-04 03:20:29 +00:00
threading.Timer(GC_INTERVAL - random.randint(0, 900), force_gc).start()