MCPcopy
hub / github.com/fastapi/fastapi / _DefaultLifespan

Class _DefaultLifespan

fastapi/routing.py:242–263  ·  view source on GitHub ↗

Default lifespan context manager that runs on_startup and on_shutdown handlers. This is a copy of the Starlette _DefaultLifespan class that was removed in Starlette. FastAPI keeps it to maintain backward compatibility with on_startup and on_shutdown event handlers. Ref: https:

Source from the content-addressed store, hash-verified

240
241
242class _DefaultLifespan:
243 """
244 Default lifespan context manager that runs on_startup and on_shutdown handlers.
245
246 This is a copy of the Starlette _DefaultLifespan class that was removed
247 in Starlette. FastAPI keeps it to maintain backward compatibility with
248 on_startup and on_shutdown event handlers.
249
250 Ref: https://github.com/Kludex/starlette/pull/3117
251 """
252
253 def __init__(self, router: "APIRouter") -> None:
254 self._router = router
255
256 async def __aenter__(self) -> None:
257 await self._router._startup()
258
259 async def __aexit__(self, *exc_info: object) -> None:
260 await self._router._shutdown()
261
262 def __call__(self: _T, app: object) -> _T:
263 return self
264
265
266# Cache for endpoint context to avoid re-extracting on every request

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…