Fix Ctrl-C handling in REPL
Python's readline module is unable to handle signals when it's called not on the main thread, and it's blocking so we can't call it from the same thread as Trio. Get rid of the additional thread and handle input ourselves.
This is extremely rough, probably misbehaves on Windows, and is probably incomplete in some interesting way. I think it also misbehaves with Python 3.14. All I can say is it mostly works on my machine (Ubuntu 24.04, system Python). I'm mostly posting here for thoughts on the general approach of calling readline via ctypes + inspiration if someone else wants to run with this and finish it.
Codecov Report
:x: Patch coverage is 77.10843% with 19 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 99.75714%. Comparing base (e590d39) to head (0e25830).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| src/trio/_repl.py | 77.10843% | 16 Missing and 3 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #3306 +/- ##
====================================================
- Coverage 100.00000% 99.75714% -0.24286%
====================================================
Files 127 127
Lines 19274 19353 +79
Branches 1304 1314 +10
====================================================
+ Hits 19274 19306 +32
- Misses 0 41 +41
- Partials 0 6 +6
| Files with missing lines | Coverage Δ | |
|---|---|---|
| src/trio/_repl.py | 77.86885% <77.10843%> (-22.13116%) |
:arrow_down: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.