Fix app stability: graceful model switching and web server improvements

- Add comprehensive error handling to prevent crashes during model reload
- Implement automatic port fallback (8080-8084) for web server conflicts
- Configure uvicorn to work properly with PyInstaller console=False builds
- Add proper web server shutdown on app close to release ports
- Improve error reporting with full tracebacks for debugging

Fixes:
- App crashing when switching models
- Web server not starting after app crash (port conflict)
- Web server failing silently in compiled builds without console

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-26 17:50:37 -08:00
parent 478146c58d
commit e831dadd24
2 changed files with 136 additions and 52 deletions

View File

@@ -223,11 +223,21 @@ class TranscriptionWebServer:
async def start(self):
"""Start the web server."""
import uvicorn
import logging
# Configure uvicorn to work without console (for PyInstaller builds)
# Suppress uvicorn's default console logging
logging.getLogger("uvicorn").setLevel(logging.ERROR)
logging.getLogger("uvicorn.access").setLevel(logging.ERROR)
logging.getLogger("uvicorn.error").setLevel(logging.ERROR)
config = uvicorn.Config(
self.app,
host=self.host,
port=self.port,
log_level="warning"
log_level="error", # Only log errors
access_log=False, # Disable access logging
log_config=None # Don't use default logging config
)
server = uvicorn.Server(config)
await server.serve()