fix: clean shutdown without hanging on Ctrl+C#118
Open
m-mcgowan wants to merge 1 commit intoJakeler:mainfrom
Open
fix: clean shutdown without hanging on Ctrl+C#118m-mcgowan wants to merge 1 commit intoJakeler:mainfrom
m-mcgowan wants to merge 1 commit intoJakeler:mainfrom
Conversation
When pressing Ctrl+C to exit, the application would sometimes hang because BLE notifications continued to queue data during shutdown, preventing the run loop from reaching its exit sentinel. Changes: - linux_pty.py: Add _stopping flag to reject writes during shutdown - linux_pty.py: Clear pending queue items before adding exit sentinel - main.py: Reorder shutdown to stop loops before cleanup - main.py: Add timeouts to prevent hanging on disconnect This ensures a clean, prompt shutdown even when BLE data is still being received. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When pressing Ctrl+C to exit, the application would sometimes hang because BLE notifications continued to queue data during shutdown, preventing the run loop from reaching its exit sentinel.
Problem
stop_loop()addsNonesentinel to the end of the queueNonesentinelSolution
linux_pty.py:
_stoppingflag to reject new writes during shutdownmain.py:
asyncio.gather()andbt.disconnect()to prevent hangingTesting
Tested on macOS with ESP32-S3 device using Nordic UART Service. Before the fix, Ctrl+C would hang when data was being received. After the fix, shutdown completes promptly.