Skip to content

Commit a30d0d0

Browse files
committed
revert: add Gunicorn preload option and initialize shared resources
This reverts commit 1af14bd.
1 parent 2a64d28 commit a30d0d0

File tree

4 files changed

+10
-41
lines changed

4 files changed

+10
-41
lines changed

apps/common/management/commands/services/services/gunicorn.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def cmd(self):
1818
bind = f'{HTTP_HOST}:{HTTP_PORT}'
1919
cmd = [
2020
'gunicorn', 'maxkb.wsgi:application',
21-
'--preload',
2221
'-b', bind,
2322
'-k', 'gthread',
2423
'--threads', '200',

apps/common/management/commands/services/services/local_model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def cmd(self):
2828
worker = CONFIG.get("LOCAL_MODEL_HOST_WORKER", 1)
2929
cmd = [
3030
'gunicorn', 'maxkb.wsgi:application',
31-
'--preload',
3231
'-b', bind,
3332
'-k', 'gthread',
3433
'--threads', '200',

apps/common/management/commands/services/services/scheduler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def cmd(self):
2020
bind = f'127.0.0.1:6060'
2121
cmd = [
2222
'gunicorn', 'maxkb.wsgi:application',
23-
'--preload',
2423
'-b', bind,
2524
'-k', 'gthread',
2625
'--threads', '200',

apps/maxkb/wsgi.py

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,29 @@
1010
import os
1111

1212
from django.core.wsgi import get_wsgi_application
13-
#
14-
# # 检查是否启用 memray 分析
15-
# if os.environ.get('ENABLE_MEMRAY') == '1':
16-
# import memray
17-
# import atexit
18-
#
19-
# # 为每个进程创建单独的追踪文件
20-
# pid = os.getpid()
21-
# output_file = f"memray_output_{pid}.bin"
22-
#
23-
# tracker = memray.Tracker(output_file)
24-
# tracker.__enter__()
25-
#
26-
#
27-
# def cleanup():
28-
# tracker.__exit__(None, None, None)
29-
#
30-
#
31-
# atexit.register(cleanup)
3213

3314
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'maxkb.settings')
3415

3516
application = get_wsgi_application()
3617

3718

38-
# -----------------------------
39-
# 全局初始化,只希望在 master preload 阶段执行一次
40-
# -----------------------------
41-
def preloaded_init():
19+
20+
def post_handler():
4221
from common.database_model_manage.database_model_manage import DatabaseModelManage
4322
from common import event
44-
from common.utils.logger import maxkb_logger
4523

4624
event.run()
4725
DatabaseModelManage.init()
4826

49-
if os.environ.get("ENABLE_SCHEDULER") == "1":
50-
from common import job
51-
52-
job.run()
5327

54-
maxkb_logger.info("✅ preloaded_init: master 初始化完成,内存将被 worker 共享")
28+
def post_scheduler_handler():
29+
from common import job
5530

31+
job.run()
5632

57-
# Gunicorn preload 阶段会执行此逻辑
58-
if os.environ.get("GUNICORN_PRELOAD", "1") == "1":
59-
try:
60-
preloaded_init()
61-
except Exception as e:
62-
import traceback
63-
from common.utils.logger import maxkb_logger
33+
# 启动后处理函数
34+
post_handler()
6435

65-
maxkb_logger.info("⚠️ preload 初始化失败:", e)
66-
traceback.print_exc()
36+
# 仅在scheduler中启动定时任务,dev local_model celery 不需要
37+
if os.environ.get('ENABLE_SCHEDULER') == '1':
38+
post_scheduler_handler()

0 commit comments

Comments
 (0)