From 87d51dd1e6cde94adf4f8fb23828e1537c4f1301 Mon Sep 17 00:00:00 2001 From: databasedav <31483365+databasedav@users.noreply.github.com> Date: Mon, 4 May 2020 15:49:44 -0700 Subject: [PATCH] ASGI startup and shutdown lifespan handlers (#468) Co-authored-by: avi --- socketio/asgi.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/socketio/asgi.py b/socketio/asgi.py index 9bcdd03..2394ee1 100644 --- a/socketio/asgi.py +++ b/socketio/asgi.py @@ -16,6 +16,10 @@ class ASGIApp(engineio.ASGIApp): # pragma: no cover :param socketio_path: The endpoint where the Socket.IO application should be installed. The default value is appropriate for most cases. + :param on_startup: function to be called on application startup; can be + coroutine + :param on_shutdown: function to be called on application shutdown; can be + coroutine Example usage:: @@ -30,7 +34,9 @@ class ASGIApp(engineio.ASGIApp): # pragma: no cover uvicorn.run(app, host='127.0.0.1', port=5000) """ def __init__(self, socketio_server, other_asgi_app=None, - static_files=None, socketio_path='socket.io'): + static_files=None, socketio_path='socket.io', + on_startup=None, on_shutdown=None): super().__init__(socketio_server, other_asgi_app, static_files=static_files, - engineio_path=socketio_path) + engineio_path=socketio_path, on_startup=on_startup, + on_shutdown=on_shutdown)