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 May 3, 2024
1 parent 344a5d0 commit 808632d
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 @@ -4,6 +4,7 @@
import re
from contextlib import asynccontextmanager
from http import HTTPStatus
from typing import Any, Set

import fastapi
import uvicorn
Expand Down Expand Up @@ -33,6 +34,8 @@
openai_serving_completion: OpenAIServingCompletion
logger = init_logger(__name__)

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


@asynccontextmanager
async def lifespan(app: fastapi.FastAPI):
Expand All @@ -43,7 +46,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)

yield

Expand Down

0 comments on commit 808632d

Please sign in to comment.