Skip to content

Commit

Permalink
[BugFix] Prevent the task of _force_log from being garbage collected (
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry authored and joerunde committed May 6, 2024
1 parent 977a6cd commit de6d42a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion vllm/entrypoints/openai/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
from contextlib import asynccontextmanager
from http import HTTPStatus
from typing import Any, Set

import fastapi
import uvicorn
Expand Down Expand Up @@ -37,6 +38,8 @@
async_llm_engine: AsyncLLMEngine
logger = init_logger(__name__)

_running_tasks: Set[asyncio.Task[Any]] = set()


@asynccontextmanager
async def lifespan(app: fastapi.FastAPI):
Expand All @@ -47,7 +50,9 @@ async def _force_log():
await engine.do_log_stats()

if not engine_args.disable_log_stats:
asyncio.create_task(_force_log())
task = asyncio.create_task(_force_log())
_running_tasks.add(task)
task.add_done_callback(_running_tasks.remove)

grpc_server = await start_grpc_server(async_llm_engine, args)

Expand Down

0 comments on commit de6d42a

Please sign in to comment.