fix: lifespan 关闭时 await 取消的采集任务,避免 pending 警告

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Sakurasan
2026-08-10 20:23:17 +08:00
co-authored by Claude
parent 6b12b04cab
commit c58bd990fd
+4
View File
@@ -21,6 +21,10 @@ async def lifespan(app: FastAPI):
yield yield
finally: finally:
collector_task.cancel() collector_task.cancel()
try:
await collector_task
except asyncio.CancelledError:
pass
app = FastAPI(title="AUV API", version="1.0.0", lifespan=lifespan) app = FastAPI(title="AUV API", version="1.0.0", lifespan=lifespan)