Fix infinite spawn loop on all platforms with PyInstaller
Extended the freeze_support fix to work on Linux and macOS, not just Windows.
The spawn loop can occur on any platform when PyInstaller bundles apps that
use multiprocessing.
Changes:
- Removed Windows-only condition for freeze_support()
- Added multiprocessing.set_start_method('spawn', force=True)
- Set spawn method for consistency across all platforms
- Prevents fork-related issues on Linux with PyInstaller
Why this is needed:
- PyTorch, faster-whisper, and RealtimeSTT all use multiprocessing
- PyInstaller frozen executables need explicit spawn method configuration
- Linux defaults to 'fork' which can cause issues with frozen executables
- 'spawn' method is more reliable with PyInstaller on all platforms
This ensures the app launches only once on Windows, Linux, and macOS.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
12
main.py
12
main.py
@@ -11,11 +11,19 @@ import sys
|
|||||||
import multiprocessing
|
import multiprocessing
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# CRITICAL: Must be called before anything else on Windows 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
|
||||||
if sys.platform == 'win32':
|
# Required on all platforms (Windows, Linux, macOS) when using multiprocessing
|
||||||
multiprocessing.freeze_support()
|
multiprocessing.freeze_support()
|
||||||
|
|
||||||
|
# Set multiprocessing start method to 'spawn' for consistency across platforms
|
||||||
|
# This prevents issues with PyInstaller frozen executables
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
multiprocessing.set_start_method('spawn', force=True)
|
||||||
|
except RuntimeError:
|
||||||
|
pass # Already set, ignore
|
||||||
|
|
||||||
# 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