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:
| 240 | |
| 241 | |
| 242 | class _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 |
no outgoing calls
no test coverage detected
searching dependent graphs…