QGIS完成初步重构
This commit is contained in:
+10
-10
@@ -22,24 +22,24 @@ async def lifespan(app: FastAPI):
|
||||
get_earthquake_model()
|
||||
logger.info("DBN模型预加载完成")
|
||||
|
||||
# 初始化 QGIS 环境
|
||||
# 检测 QGIS 子进程环境
|
||||
qgis_root = getattr(settings, "QGIS_ROOT", None)
|
||||
if qgis_root:
|
||||
try:
|
||||
from app.services.qgis.qgis_env import init_qgis_env
|
||||
init_qgis_env(qgis_root)
|
||||
logger.info("QGIS 环境初始化完成")
|
||||
from app.services.qgis.qgis_env import is_qgis_available
|
||||
if is_qgis_available(qgis_root):
|
||||
logger.info("QGIS 环境检测通过(子进程模式)")
|
||||
else:
|
||||
logger.warning("QGIS 环境不可用(未找到 Python 3.12 解释器),专题图功能降级")
|
||||
except Exception as e:
|
||||
logger.error(f"QGIS 环境初始化失败(专题图功能不可用): {e}")
|
||||
logger.error(f"QGIS 环境检测失败: {e}")
|
||||
|
||||
yield
|
||||
|
||||
# 清理 QGIS 资源
|
||||
# 清理资源
|
||||
try:
|
||||
from app.services.qgis.qgis_env import cleanup_qgis_env
|
||||
from app.services.qgis.map_service import template_cache
|
||||
template_cache.cleanup()
|
||||
cleanup_qgis_env()
|
||||
from app.api.qgis_map_export import shutdown_thread_pool
|
||||
shutdown_thread_pool()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user