Fix recording failure in Windows PyInstaller builds with console=False
When console=False in PyInstaller builds on Windows, stdout/stderr are not available. This causes subprocess/multiprocessing operations to fail when they try to write output, breaking RealtimeSTT initialization. The fix: - Check if running as frozen executable on Windows - Test if stdout/stderr are available (try to flush) - If not available, redirect to io.StringIO() null streams - This allows subprocess/multiprocessing to write without errors This fixes the "Failed to start Recording" error that only occurred in builds with console=False but worked fine with console=True or when running with uv. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
16
main.py
16
main.py
@@ -10,6 +10,7 @@ optional multi-user server synchronization.
|
|||||||
import sys
|
import sys
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
# CRITICAL: Must be called before anything else with PyInstaller
|
# CRITICAL: Must be called before anything else with PyInstaller
|
||||||
# This prevents the infinite spawning loop when the frozen executable runs
|
# This prevents the infinite spawning loop when the frozen executable runs
|
||||||
@@ -24,6 +25,21 @@ if __name__ == "__main__":
|
|||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass # Already set, ignore
|
pass # Already set, ignore
|
||||||
|
|
||||||
|
# Fix for Windows PyInstaller builds with console=False
|
||||||
|
# When console is hidden, subprocess/multiprocessing can't write to stdout/stderr
|
||||||
|
# This causes RealtimeSTT and other libraries to fail silently
|
||||||
|
if getattr(sys, 'frozen', False) and sys.platform == 'win32':
|
||||||
|
# Redirect stdout/stderr to null device on Windows when frozen
|
||||||
|
# Only if they're not already valid (console=False builds)
|
||||||
|
try:
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.stderr.flush()
|
||||||
|
except (AttributeError, OSError):
|
||||||
|
# stdout/stderr are not available, redirect to null
|
||||||
|
import io
|
||||||
|
sys.stdout = io.StringIO()
|
||||||
|
sys.stderr = io.StringIO()
|
||||||
|
|
||||||
# Add project root to Python path
|
# Add project root to Python path
|
||||||
project_root = Path(__file__).parent
|
project_root = Path(__file__).parent
|
||||||
sys.path.insert(0, str(project_root))
|
sys.path.insert(0, str(project_root))
|
||||||
|
|||||||
Reference in New Issue
Block a user