From ce8fad85868ed6551b821796771e496331b77dbc Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Wed, 5 Feb 2025 23:10:34 +0300 Subject: [PATCH] Simplify lifespan context manager for background task management --- api_server.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/api_server.py b/api_server.py index 0727f32..23c7e84 100644 --- a/api_server.py +++ b/api_server.py @@ -33,19 +33,13 @@ Config = get_settings() @asynccontextmanager async def lifespan(_: FastAPI): await client.start() - - # Start background task - background_task = asyncio.create_task(cache_media_files()) - + background_task = asyncio.create_task(cache_media_files()) # Start background task yield - - # Cleanup - background_task.cancel() + background_task.cancel() # Cleanup try: await background_task except asyncio.CancelledError: pass - await client.stop() app = FastAPI( title="Pyrogram Bridge", lifespan=lifespan)