MCPcopy Index your code
hub / github.com/vastsa/FileCodeBox / lifespan

Function lifespan

main.py:689–711  ·  view source on GitHub ↗
(app: FastAPI)

Source from the content-addressed store, hash-verified

687
688@asynccontextmanager
689async def lifespan(app: FastAPI):
690 logger.info("正在初始化应用...")
691 # 初始化数据库
692 await init_db()
693
694 # 加载配置(多进程下串行化启动写操作)
695 async with db_startup_lock():
696 await load_config()
697 # 启动后台任务
698 task = asyncio.create_task(delete_expire_files())
699 chunk_cleanup_task = asyncio.create_task(clean_incomplete_uploads())
700 logger.info("应用初始化完成")
701
702 try:
703 yield
704 finally:
705 # 清理操作
706 logger.info("正在关闭应用...")
707 task.cancel()
708 chunk_cleanup_task.cancel()
709 await asyncio.gather(task, chunk_cleanup_task, return_exceptions=True)
710 await Tortoise.close_connections()
711 logger.info("应用已关闭")
712
713
714async def load_config():

Callers

nothing calls this directly

Calls 5

init_dbFunction · 0.90
db_startup_lockFunction · 0.90
delete_expire_filesFunction · 0.90
clean_incomplete_uploadsFunction · 0.90
load_configFunction · 0.85

Tested by

no test coverage detected