INNER CODE UNIT · Python
_application_lifespan
CronusL-1141/AI-company · src/aiteam/api/app.py:119
async def _application_lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
"""Application lifecycle management."""
mcp_app = _get_mcp_http_app()
if mcp_app is not None:
# FastAPI mount() does NOT trigger sub-app lifespan automatically.
# We must enter it here so StreamableHTTPSessionManager._task_group
# is initialized before the first request arrives.
async with mcp_app.lifespan(mcp_app):
await init_dependencies()
try:
async with account_monitor_lifespan(app, DEFAULT_DB_URL):
yield
finally:
await cleanup_dependencies()
else:
await init_dependencies()
try:
async with account_monitor_lifespan(app, DEFAULT_DB_URL):