2025-11-05 11:05:26 +00:00
|
|
|
|
# coding=utf-8
|
2025-04-14 12:11:23 +00:00
|
|
|
|
"""
|
2025-11-05 11:05:26 +00:00
|
|
|
|
@project: MaxKB
|
|
|
|
|
|
@Author:虎虎
|
|
|
|
|
|
@file: web.py
|
|
|
|
|
|
@date:2025/11/5 15:14
|
|
|
|
|
|
@desc:
|
2025-04-14 12:11:23 +00:00
|
|
|
|
"""
|
2025-11-06 12:17:21 +00:00
|
|
|
|
import builtins
|
2025-04-14 12:11:23 +00:00
|
|
|
|
import os
|
2025-11-06 12:17:21 +00:00
|
|
|
|
import sys
|
2025-04-14 12:11:23 +00:00
|
|
|
|
|
|
|
|
|
|
from django.core.wsgi import get_wsgi_application
|
|
|
|
|
|
|
2025-11-06 12:17:21 +00:00
|
|
|
|
|
|
|
|
|
|
class TorchBlocker:
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
self.original_import = builtins.__import__
|
|
|
|
|
|
|
|
|
|
|
|
def __call__(self, name, *args, **kwargs):
|
|
|
|
|
|
if len([True for i in
|
|
|
|
|
|
['torch']
|
|
|
|
|
|
if
|
|
|
|
|
|
i in name.lower()]) > 0:
|
|
|
|
|
|
print(f"Disable package is being imported: 【{name}】", file=sys.stderr)
|
|
|
|
|
|
pass
|
|
|
|
|
|
else:
|
|
|
|
|
|
return self.original_import(name, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 安装导入拦截器
|
|
|
|
|
|
builtins.__import__ = TorchBlocker()
|
|
|
|
|
|
|
2025-04-14 12:11:23 +00:00
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'maxkb.settings')
|
|
|
|
|
|
|
|
|
|
|
|
application = get_wsgi_application()
|
2025-07-02 03:44:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
2025-11-05 08:39:41 +00:00
|
|
|
|
def post_handler():
|
2025-07-02 03:44:33 +00:00
|
|
|
|
from common.database_model_manage.database_model_manage import DatabaseModelManage
|
|
|
|
|
|
from common import event
|
|
|
|
|
|
|
|
|
|
|
|
event.run()
|
|
|
|
|
|
DatabaseModelManage.init()
|
|
|
|
|
|
|
2025-07-17 05:24:59 +00:00
|
|
|
|
|
2025-11-05 08:39:41 +00:00
|
|
|
|
def post_scheduler_handler():
|
|
|
|
|
|
from common import job
|
2025-07-21 07:44:54 +00:00
|
|
|
|
|
2025-11-05 08:39:41 +00:00
|
|
|
|
job.run()
|
2025-07-21 07:44:54 +00:00
|
|
|
|
|
2025-11-06 12:17:21 +00:00
|
|
|
|
|
2025-11-05 08:39:41 +00:00
|
|
|
|
# 启动后处理函数
|
|
|
|
|
|
post_handler()
|
2025-07-17 05:24:59 +00:00
|
|
|
|
|
2025-11-05 08:39:41 +00:00
|
|
|
|
# 仅在scheduler中启动定时任务,dev local_model celery 不需要
|
|
|
|
|
|
if os.environ.get('ENABLE_SCHEDULER') == '1':
|
2025-11-06 12:17:21 +00:00
|
|
|
|
post_scheduler_handler()
|