Wie füge ich mit Lebensdauer in Middleware ein Shutdown -Ereignis in Fastapi hinzu?Python

Python-Programme
Anonymous
 Wie füge ich mit Lebensdauer in Middleware ein Shutdown -Ereignis in Fastapi hinzu?

Post by Anonymous »

Fastapi Profiler Code < /p>

Code: Select all

        if server_app is not None:
server_app.add_event_handler("shutdown", self.get_profiler_result)
< /code>
Ich denke, Starlette erlaubt nicht sowohl Lebensdauer als auch Abschalten von Ereignissen.        if on_startup or on_shutdown:
warnings.warn(
"The on_startup and on_shutdown parameters are deprecated, and they "
"will be removed on version 1.0. Use the lifespan parameter instead. "
"See more about it on https://www.starlette.io/lifespan/.",
DeprecationWarning,
)
if lifespan:
warnings.warn(
"The `lifespan` parameter cannot be used with `on_startup` or "
"`on_shutdown`. Both `on_startup` and `on_shutdown` will be "
"ignored."
)
< /code>
Ich verwende die Lebensdauer, um meine DB zu verwalten, und das kann nicht entfernt werden. Können Sie einen Weg vorschlagen? Zum Verknüpfen, aber dieses Ereignis nicht erhalten.app = FastAPI(
lifespan=lifespan,
)

app.add_middleware(PyInstrumentProfilerMiddleware,
profiler_output_type="html",
server_app=app,
open_in_browser=True)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post