Setup: show progress while stopping the running services
After confirming, setup stops the old services and waits up to 30s for their ports to free, with no output. Show a spinner with elapsed seconds immediately (a plain line when not on a terminal), ending in a check mark. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QaE1hpvyZTJixEbUUMj9Ca
This commit is contained in:
parent
b07af69afa
commit
458b0cfc32
1 changed files with 47 additions and 7 deletions
|
|
@ -6,6 +6,7 @@ import shutil
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
|
|
@ -19,6 +20,44 @@ def say(msg=""):
|
||||||
print(msg, flush=True)
|
print(msg, flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
class Spinner:
|
||||||
|
"""Shows that a slow step is running: a spinner with elapsed seconds on a terminal,
|
||||||
|
a plain line otherwise. Ends with a check mark and how long it took."""
|
||||||
|
FRAMES = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
|
||||||
|
|
||||||
|
def __init__(self, msg):
|
||||||
|
self.msg = msg
|
||||||
|
self.tty = sys.stdout.isatty()
|
||||||
|
self._stop = threading.Event()
|
||||||
|
|
||||||
|
def _spin(self):
|
||||||
|
i = 0
|
||||||
|
while not self._stop.wait(0.1):
|
||||||
|
sys.stdout.write(f"\r{self.FRAMES[i % len(self.FRAMES)]} {self.msg}… {time.time() - self.t0:.0f}s ")
|
||||||
|
sys.stdout.flush()
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.t0 = time.time()
|
||||||
|
if self.tty:
|
||||||
|
sys.stdout.write(f"\n{self.FRAMES[0]} {self.msg}…")
|
||||||
|
sys.stdout.flush()
|
||||||
|
self._thread = threading.Thread(target=self._spin, daemon=True)
|
||||||
|
self._thread.start()
|
||||||
|
else:
|
||||||
|
say(f"\n{self.msg}…")
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, *exc):
|
||||||
|
if self.tty:
|
||||||
|
self._stop.set()
|
||||||
|
self._thread.join()
|
||||||
|
mark = "✗" if exc[0] else "✓"
|
||||||
|
sys.stdout.write(f"\r\033[K{mark} {self.msg} ({time.time() - self.t0:.0f}s)\n")
|
||||||
|
sys.stdout.flush()
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def backend_module(name):
|
def backend_module(name):
|
||||||
if name == "vllm":
|
if name == "vllm":
|
||||||
from .backends import vllm
|
from .backends import vllm
|
||||||
|
|
@ -102,13 +141,14 @@ def cmd_setup(a):
|
||||||
# MLX needs two ports: the proxy, and mlx_lm.server on the next one.
|
# MLX needs two ports: the proxy, and mlx_lm.server on the next one.
|
||||||
api_span = 2 if p["backend"] == "mlx" else 1
|
api_span = 2 if p["backend"] == "mlx" else 1
|
||||||
if not a.no_start:
|
if not a.no_start:
|
||||||
for name in service.NAMES:
|
with Spinner("Stopping llm-host's running services"):
|
||||||
service.stop(name)
|
for name in service.NAMES:
|
||||||
# Stopping returns before the old processes have let go of their ports (launchd
|
service.stop(name)
|
||||||
# especially), so wait for our own ports to close before checking what's free.
|
# Stopping returns before the old processes have let go of their ports (launchd
|
||||||
if old.get("api_port"):
|
# especially), so wait for our own ports to close before checking what's free.
|
||||||
ours = list(range(old["api_port"], old["api_port"] + api_span)) + [old.get("web_port", 8080)]
|
if old.get("api_port"):
|
||||||
wait_ports_free(ours, timeout=30)
|
ours = list(range(old["api_port"], old["api_port"] + api_span)) + [old.get("web_port", 8080)]
|
||||||
|
wait_ports_free(ours, timeout=30)
|
||||||
# Ports saved by an earlier setup are pinned: clients are configured with them, so a
|
# Ports saved by an earlier setup are pinned: clients are configured with them, so a
|
||||||
# busy saved port is an error, never a reason to move. Only a first install auto-picks.
|
# busy saved port is an error, never a reason to move. Only a first install auto-picks.
|
||||||
api_port = choose_port("API", a.api_port, old.get("api_port", 8000), api_span, a.no_start,
|
api_port = choose_port("API", a.api_port, old.get("api_port", 8000), api_span, a.no_start,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue