-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Frontend] Reapply "Factor out code for running uvicorn" (#7095)
- Loading branch information
1 parent
7b86e7c
commit cc08fc7
Showing
3 changed files
with
125 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import asyncio | ||
import signal | ||
from typing import Any | ||
|
||
import uvicorn | ||
from fastapi import FastAPI | ||
|
||
from vllm.logger import init_logger | ||
|
||
logger = init_logger(__name__) | ||
|
||
|
||
async def serve_http(app: FastAPI, **uvicorn_kwargs: Any): | ||
logger.info("Available routes are:") | ||
for route in app.routes: | ||
methods = getattr(route, "methods", None) | ||
path = getattr(route, "path", None) | ||
|
||
if methods is None or path is None: | ||
continue | ||
|
||
logger.info("Route: %s, Methods: %s", path, ', '.join(methods)) | ||
|
||
config = uvicorn.Config(app, **uvicorn_kwargs) | ||
server = uvicorn.Server(config) | ||
|
||
loop = asyncio.get_running_loop() | ||
|
||
server_task = loop.create_task(server.serve()) | ||
|
||
def signal_handler() -> None: | ||
# prevents the uvicorn signal handler to exit early | ||
server_task.cancel() | ||
|
||
async def dummy_shutdown() -> None: | ||
pass | ||
|
||
loop.add_signal_handler(signal.SIGINT, signal_handler) | ||
loop.add_signal_handler(signal.SIGTERM, signal_handler) | ||
|
||
try: | ||
await server_task | ||
return dummy_shutdown() | ||
except asyncio.CancelledError: | ||
logger.info("Gracefully stopping http server") | ||
return server.shutdown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters