Add ASGI lifespan events (Fixes #322)

This commit is contained in:
Miguel Grinberg
2025-11-23 00:08:29 +00:00
parent ae9f237ce6
commit f128b3ded4
3 changed files with 145 additions and 1 deletions

View File

@@ -722,6 +722,18 @@ runs the web application using the Uvicorn web server::
When using the ASGI support, the ``scope`` dictionary provided by the web
server is available to request handlers as ``request.asgi_scope``.
The application instance can be initialized with ``lifespan_startup`` and
``lifespan_shutdown`` arguments, which are invoked when the web server sends
the ASGI lifespan signals with the ASGI scope as only argument::
async def startup(scope):
pass
async def shutdown(scope):
pass
app = Microdot(lifespan_startup=startup, lifespan_shutdown=shutdown)
Using a WSGI Web Server
^^^^^^^^^^^^^^^^^^^^^^^