def __del__(self): # LifespanOn's logger logs in INFO level thus becomes spammy # Within this block we temporarily uplevel for cleaner logging with LoggingContext(self._serve_asgi_lifespan.logger, level=logging.WARNING): asyncio.get_event_loop().run_until_complete( self._serve_asgi_lifespan.shutdown())
async def __del__(self): # LifespanOn's logger logs in INFO level thus becomes spammy # Within this block we temporarily uplevel for cleaner logging with LoggingContext(self._serve_asgi_lifespan.logger, level=logging.WARNING): await self._serve_asgi_lifespan.shutdown() # Make sure to call user's del method as well. super_cls = super() if hasattr(super_cls, "__del__"): super_cls.__del__()
async def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._serve_app = frozen_app # Use uvicorn's lifespan handling code to properly deal with # startup and shutdown event. self._serve_asgi_lifespan = LifespanOn( Config(self._serve_app, lifespan="on")) # Replace uvicorn logger with our own. self._serve_asgi_lifespan.logger = logger # LifespanOn's logger logs in INFO level thus becomes spammy # Within this block we temporarily uplevel for cleaner logging with LoggingContext(self._serve_asgi_lifespan.logger, level=logging.WARNING): await self._serve_asgi_lifespan.startup()