Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(serve): Add graceful Ctrl+C handling with exit message (#1238)
# Graceful Ctrl+C Handling Implements reliable Ctrl+C handling for BAML's Python interface with a clean shutdown message. This fixes issues with signal handling across the Python/Rust boundary and improves user experience when stopping BAML processes. ## Changes - Added custom signal handling using the `ctrlc` crate - Implemented clean "Shutting Down BAML..." message on interrupt - Bypassed Python's signal handling to ensure reliable behavior - Added proper exit code (130) following Unix conventions - Added detailed documentation explaining the implementation ## Testing - Tested Python CLI server start/stop - Manual Ctrl+C testing in various scenarios - Verified clean shutdown message display - Tested cross-platform signal handling behavior ## Technical Details - Uses `ctrlc` crate for reliable cross-platform signal handling - Implements channel-based communication between signal handler and main thread - Follows Unix conventions for interrupt handling (exit code 130) - Properly documented implementation rationale and technical decisions ## Notes - While this is a workaround, it provides reliable interrupt handling without requiring major architectural changes - The implementation bypasses Python's signal handling entirely to avoid conflicts - Future improvements could involve deeper integration with BAML's architecture <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Enhances BAML's Python interface with reliable Ctrl+C handling and clean shutdown message using the `ctrlc` crate. > > - **Behavior**: > - Implements custom signal handling to bypass Python's signal handlers > - Displays "Shutting Down BAML..." message on interrupt > - Ensures proper process termination with standard exit codes > - **Implementation**: > - Uses `ctrlc` crate for cross-platform signal handling > - Implements channel-based communication for safe signal handling > - Follows Unix conventions with exit code 130 for SIGINT > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for the latest commit. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
- Loading branch information