Skip to content

Refactor SIGINT handling for PyInstaller Linux builds#1516

Merged
maurosoria merged 2 commits intomasterfrom
claude/improve-code-readability-SJCaF
Feb 2, 2026
Merged

Refactor SIGINT handling for PyInstaller Linux builds#1516
maurosoria merged 2 commits intomasterfrom
claude/improve-code-readability-SJCaF

Conversation

@maurosoria
Copy link
Copy Markdown
Owner

Description

This PR refactors the SIGINT (Ctrl+C) handling logic in the Controller class to improve code maintainability and clarity, particularly for PyInstaller Linux builds which have special signal handling requirements.

What will it do?

  • Extract magic numbers to constants: Moves hardcoded values (0.8 second window and 3 press threshold) to configurable constants in settings.py (SIGINT_WINDOW_SECONDS and SIGINT_FORCE_QUIT_THRESHOLD)
  • Improve code organization: Splits the monolithic handle_pause() method by extracting force quit detection into a dedicated _check_force_quit() method
  • Add helper methods: Introduces _init_sigint_tracking() and _reset_sigint_tracking() for clearer intent and easier testing
  • Enhance documentation: Adds comprehensive docstrings explaining the PyInstaller Linux-specific behavior and why special handling is needed
  • Improve code comments: Clarifies the purpose of each signal tracking variable with inline comments

Why these changes?

The original implementation had signal handling logic tightly coupled with pause handling, making it difficult to understand and maintain. The PyInstaller Linux builds require special handling for Ctrl+C due to signal delivery limitations - they need multiple rapid presses to force quit rather than a single press. These changes make that requirement explicit and configurable.

Behavior

No functional changes - the behavior remains identical:

  • Standard platforms: Single Ctrl+C during pause triggers immediate force quit
  • PyInstaller Linux: Requires 3 rapid Ctrl+C presses (within 0.8 seconds) to force quit

Requirements

  • Add your name to CONTRIBUTORS.md
  • If this is a new feature, then please add some additional information about it to CHANGELOG.md

https://claude.ai/code/session_01TYquHvVTvgoFzvdinTJF9K

- Extract magic numbers (0.8s, 3 presses) to named constants in settings.py
- Add docstrings to _is_pyinstaller_linux() and signal handling methods
- Extract force quit logic into dedicated _check_force_quit() method
- Add helper methods _init_sigint_tracking() and _reset_sigint_tracking()
- Improve inline comments for signal handling state variables

https://claude.ai/code/session_01TYquHvVTvgoFzvdinTJF9K
Replace conditional platform checks with polymorphic ForceQuitHandler classes:
- ForceQuitHandler: Base class defining the interface
- StandardForceQuitHandler: Immediate exit on Ctrl+C during pause
- PyInstallerLinuxForceQuitHandler: Multi-press detection for Linux builds

Uses factory function _create_force_quit_handler() to select the right
strategy at initialization, eliminating repeated platform checks.

https://claude.ai/code/session_01TYquHvVTvgoFzvdinTJF9K
@maurosoria maurosoria merged commit 5c9d58a into master Feb 2, 2026
5 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants