Fix model switching crash and improve error handling

**Model Reload Fixes:**
- Properly disconnect signals before reconnecting to prevent duplicate connections
- Wait for previous model loader thread to finish before starting new one
- Add garbage collection after unloading model to free memory
- Improve error handling in model reload callback

**Settings Dialog:**
- Remove duplicate success message (callback handles it)
- Only show message if no callback is defined

**Transcription Engine:**
- Explicitly delete model reference before setting to None
- Force garbage collection to ensure memory is freed

This prevents crashes when switching models, especially when done
multiple times in succession or while the app is under load.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-27 06:28:40 -08:00
parent 146a8c8beb
commit bd0e84c5e7
3 changed files with 45 additions and 22 deletions

View File

@@ -221,9 +221,16 @@ class TranscriptionEngine:
def unload_model(self):
"""Unload the model from memory."""
with self.model_lock:
if self.model is not None:
# Delete the model reference
del self.model
self.model = None
self.is_loaded = False
# Force garbage collection to free memory
import gc
gc.collect()
def __repr__(self) -> str:
return f"TranscriptionEngine(model={self.model_size}, device={self.device}, loaded={self.is_loaded})"