Review fixes: CUDA restore in finally, os._exit on Windows, taskkill /T for process tree, build-server-cuda error handling, db-init path

This commit is contained in:
Jamie Pine
2026-03-15 05:43:26 -07:00
parent f1ba73a386
commit e239be5bbb
3 changed files with 25 additions and 16 deletions
+12 -11
View File
@@ -168,17 +168,18 @@ def build_server(cuda=False):
restore_cuda = True restore_cuda = True
# Run PyInstaller # Run PyInstaller
PyInstaller.__main__.run(args) try:
PyInstaller.__main__.run(args)
# Restore CUDA torch if we swapped it out finally:
if restore_cuda: # Restore CUDA torch if we swapped it out (even on build failure)
print("Restoring CUDA torch...") if restore_cuda:
import subprocess print("Restoring CUDA torch...")
subprocess.run( import subprocess
[sys.executable, "-m", "pip", "install", "torch", "torchvision", "torchaudio", subprocess.run(
"--index-url", "https://download.pytorch.org/whl/cu126", "--force-reinstall", "-q"], [sys.executable, "-m", "pip", "install", "torch", "torchvision", "torchaudio",
check=True "--index-url", "https://download.pytorch.org/whl/cu126", "--force-reinstall", "-q"],
) check=True
)
print(f"Binary built in {backend_dir / 'dist' / binary_name}") print(f"Binary built in {backend_dir / 'dist' / binary_name}")
+7 -1
View File
@@ -119,7 +119,13 @@ def _start_parent_watchdog(parent_pid, data_dir=None):
while True: while True:
if not _is_pid_alive(parent_pid): if not _is_pid_alive(parent_pid):
watchdog_logger.info(f"Parent process {parent_pid} gone, shutting down server...") watchdog_logger.info(f"Parent process {parent_pid} gone, shutting down server...")
os.kill(os.getpid(), signal.SIGTERM) if sys.platform == "win32":
# sys.exit triggers SystemExit, allowing uvicorn to run
# shutdown handlers. os.kill(SIGTERM) on Windows calls
# TerminateProcess which hard-kills without cleanup.
os._exit(0)
else:
os.kill(os.getpid(), signal.SIGTERM)
return return
time.sleep(2) time.sleep(2)
+6 -4
View File
@@ -114,7 +114,7 @@ dev: _ensure-venv _ensure-sidecar
Start-Sleep -Seconds 2; \ Start-Sleep -Seconds 2; \
}; \ }; \
Write-Host "Starting Tauri desktop app..."; \ Write-Host "Starting Tauri desktop app..."; \
try { Set-Location "{{ tauri_dir }}"; bun run tauri dev } finally { if ($backendJob) { Stop-Process -Id $backendJob.Id -Force -ErrorAction SilentlyContinue } } try { Set-Location "{{ tauri_dir }}"; bun run tauri dev } finally { if ($backendJob) { taskkill /PID $backendJob.Id /T /F 2>$null | Out-Null } }
# Start backend only # Start backend only
[unix] [unix]
@@ -163,7 +163,7 @@ dev-web: _ensure-venv
Start-Sleep -Seconds 2; \ Start-Sleep -Seconds 2; \
}; \ }; \
Write-Host "Starting web app..."; \ Write-Host "Starting web app..."; \
try { Set-Location "{{ web_dir }}"; bun run dev } finally { if ($backendJob) { Stop-Process -Id $backendJob.Id -Force -ErrorAction SilentlyContinue } } try { Set-Location "{{ web_dir }}"; bun run dev } finally { if ($backendJob) { taskkill /PID $backendJob.Id /T /F 2>$null | Out-Null } }
# Kill all dev processes # Kill all dev processes
[unix] [unix]
@@ -201,8 +201,10 @@ build-server: _ensure-venv
# Build CUDA server binary and place in app data dir for local testing # Build CUDA server binary and place in app data dir for local testing
[windows] [windows]
build-server-cuda: _ensure-venv build-server-cuda: _ensure-venv
$ErrorActionPreference = "Stop"; \
$env:PATH = "{{ venv_bin }};$env:PATH"; \ $env:PATH = "{{ venv_bin }};$env:PATH"; \
& "{{ python }}" backend/build_binary.py --cuda; \ & "{{ python }}" backend/build_binary.py --cuda; \
if ($LASTEXITCODE -ne 0) { throw "build_binary.py --cuda failed with exit code $LASTEXITCODE" }; \
$dest = "$env:APPDATA/com.voicebox.app/backends"; \ $dest = "$env:APPDATA/com.voicebox.app/backends"; \
New-Item -ItemType Directory -Path $dest -Force | Out-Null; \ New-Item -ItemType Directory -Path $dest -Force | Out-Null; \
Copy-Item "backend/dist/voicebox-server-cuda.exe" "$dest/voicebox-server-cuda.exe" -Force; \ Copy-Item "backend/dist/voicebox-server-cuda.exe" "$dest/voicebox-server-cuda.exe" -Force; \
@@ -253,11 +255,11 @@ fix:
# Initialize SQLite database # Initialize SQLite database
[unix] [unix]
db-init: _ensure-venv db-init: _ensure-venv
cd {{ backend_dir }} && {{ python }} -c "from database import init_db; init_db()" {{ python }} -c "from backend.database import init_db; init_db()"
[windows] [windows]
db-init: _ensure-venv db-init: _ensure-venv
Set-Location "{{ backend_dir }}"; & "{{ python }}" -c "from database import init_db; init_db()" & "{{ python }}" -c "from backend.database import init_db; init_db()"
# Reset database (delete + reinit) # Reset database (delete + reinit)
[unix] [unix]