MCPcopy
hub / github.com/fastapi/fastapi / add_event_handler

Method add_event_handler

fastapi/routing.py:6345–6362  ·  view source on GitHub ↗

Add an event handler function for startup or shutdown. This method is kept for backward compatibility after Starlette removed support for on_startup/on_shutdown handlers. Ref: https://github.com/Kludex/starlette/pull/3117

(
        self,
        event_type: str,
        func: Callable[[], Any],
    )

Source from the content-addressed store, hash-verified

6343
6344 # TODO: remove this once the lifespan (or alternative) interface is improved
6345 def add_event_handler(
6346 self,
6347 event_type: str,
6348 func: Callable[[], Any],
6349 ) -> None:
6350 """
6351 Add an event handler function for startup or shutdown.
6352
6353 This method is kept for backward compatibility after Starlette removed
6354 support for on_startup/on_shutdown handlers.
6355
6356 Ref: https://github.com/Kludex/starlette/pull/3117
6357 """
6358 assert event_type in ("startup", "shutdown")
6359 if event_type == "startup":
6360 self.on_startup.append(func)
6361 else:
6362 self.on_shutdown.append(func)
6363
6364 @deprecated(
6365 """

Callers 2

include_routerMethod · 0.95
decoratorMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected