Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions online_server/online_server/env_instance_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import subprocess
import threading
from datetime import datetime
from fastapi import FastAPI
from fastapi import FastAPI, HTTPException
from typing import List
import heapq
import psutil
Expand Down Expand Up @@ -97,9 +97,10 @@ def __init__(self, cwd: str, port: int, logfile_dir: str):
def start(self):
self.start_time = time.time()
log_file = os.path.join(self.logfile_dir, f'env_{self.port}.log')
bind_host = os.environ.get("SERVER_BIND_HOST", "::")
self.proc = PortMonitor.start(
cmd=["uvicorn", "env_server:app", "--port",
str(self.port), "--host", "::", "--workers", "1"],
str(self.port), "--host", bind_host, "--workers", "1"],
cwd=self.cwd,
port=self.port,
log_file=log_file)
Expand Down Expand Up @@ -246,7 +247,15 @@ async def lifespan(app: FastAPI):

@app.get("/get_instance")
def get_instance():
inst = EnvInstanceManager.get_instance()
try:
inst = EnvInstanceManager.get_instance()
except Exception as exc:
if "No available resources to allocate" in str(exc):
raise HTTPException(
status_code=503,
detail="No available resources to allocate.",
) from exc
raise
return {"uid": inst.uid, "port": inst.get_port()}


Expand All @@ -266,4 +275,4 @@ def release_instance(uid: str):
app.state.workers = args.workers

import uvicorn
uvicorn.run(app, host="::", port=8000)
uvicorn.run(app, host=os.environ.get("SERVER_BIND_HOST", "::"), port=8000)