UnisKB/apps/maxkb/settings/mem.py

23 lines
585 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
2025-11-04 05:33:22 +00:00
def enable_force_gc():
2025-11-04 01:31:27 +00:00
collected = gc.collect()
maxkb_logger.debug(f"(PID: {CURRENT_PID}) Forced GC ({collected} objects collected)")
2025-11-04 05:35:53 +00:00
t = threading.Timer(GC_INTERVAL - random.randint(0, 900), enable_force_gc)
2025-11-04 05:33:22 +00:00
t.daemon = True
t.start()
2025-11-04 01:31:27 +00:00
2025-11-04 06:00:32 +00:00
if CONFIG.get("ENABLE_FORCE_GC", '1') == "1":
2025-11-04 05:56:20 +00:00
maxkb_logger.info(f"(PID: {CURRENT_PID}) Forced GC enabled")
2025-11-04 05:33:22 +00:00
enable_force_gc()