tools: Only issue a single Ctrl-C when entering raw REPL. #15991
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
A long time ago when there was only the
stm
port, Ctrl-C would trigger a preemptive NLR jump to break out of running code. Then in commit 124df6f a more general approach to asynchronousKeyboardInterrupt
exceptions was implemented, andstmhal
supported both approaches, with the general (soft) interrupt taking priority.Then in commit bc1488a
pyboard.py
was updated with a corresponding change to make it issue a double Ctrl-C to break out of any existing code when entering the raw REPL (two Ctrl-C characters were sent in order to more reliably trigger the preemptive NLR jump).No other port has preemptive NLR jumps and so a double Ctrl-C doesn't really behave any differently to a single Ctrl-C: with USB CDC the double Ctrl-C would most likely be in the same USB packet and so processed in the same low-level USB callback, so it's just setting the keyboard interrupt flag twice in a row. The VM/runtime then just sees one keyboard interrupt and acts as though only one Ctrl-C was sent.
This commit changes the double Ctrl-C to a single Ctrl-C in
pyboard.py
andmpremote
. That keeps things as simple as they need to be.Testing
Ran the test suite on a PYBD-SF2 and ESP32_GENERIC board. It passes.
Also ran the
mpremote
tests on the same hardware. They also pass.Trade-offs and Alternatives
There's a slight risk this may change behaviour of some code which expects two Ctrl-C's, but that's unlikely because in the vast majority of cases two back-to-back Ctrl-C's will just end up being one
KeyboardInterrupt
, ie equivalent to a single Ctrl-C (especially due to #15988 that preemptive NLR jump is removed).