-
-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve REPL KI #3030
base: main
Are you sure you want to change the base?
Improve REPL KI #3030
Conversation
Codecov ReportAttention: Patch coverage is
❌ Your project check has failed because the head coverage (56.15561%) is below the target coverage (100.00000%). You can increase the head coverage or adjust the target coverage.
Additional details and impacted files@@ Coverage Diff @@
## main #3030 +/- ##
=====================================================
- Coverage 100.00000% 56.15561% -43.84439%
=====================================================
Files 124 246 +122
Lines 18764 37608 +18844
Branches 1269 2540 +1271
=====================================================
+ Hits 18764 21119 +2355
- Misses 0 16361 +16361
- Partials 0 128 +128
🚀 New features to boost your workflow:
|
Could we spawn the REPL as another process and send it a signal? (simulate ctrl+c) I think we could first send it some data over stdin to get into specific scenarios. |
The newline is sent to the terminal I think, rather than any specific process. Potentially we could avoid the ioctl weirdness by allowing a small amount of user discomfort in needing to press enter after Ctrl+C. |
Still no idea how to test the proposed fixes. I think it's relevant that asyncio isn't able to interrupt the input thread either, unless it's using the new python repl: Was there ever talk about the |
src/trio/_repl.py
Outdated
nonlocal interrupted | ||
interrupted = True | ||
# Fake up a newline char as if user had typed it at terminal | ||
fcntl.ioctl(sys.stdin, termios.TIOCSTI, b"\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can't write to sys.stdin from a handler safely, I'm not sure if you can icotl to the .fileno() or not either, I think you need:
@disable_ki_protection
def _newline():
# Fake up a newline char as if user had typed it at terminal
fcntl.ioctl(sys.stdin, termios.TIOCSTI, b"\n")
class TrioInteractiveConsole:
token = trio.lowlevel.current_trio_token()
def handler(...):
nonlocal interrupted
interrupted = True
token.run_sync_soon(_newline, idempotent=True)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think I understand why, but won't a keyboard interrupt in the newline function blow up trio and end the repl? If so, Would suppressing the exception be sufficient?
74760af
to
620a5c0
Compare
02ae29d
to
a5dcdbf
Compare
Uh turns out pyrepl is a separate package that cpython vendored: https://pypi.org/project/pyrepl/#history I have no intention of vendoring it or making a dependency for this pr but just FYI |
This commit has a draft method to fix #3007. I have 0 ideas on how to test this thing: not only does it use the
raw_input
that gets patched for testing, but the way it injects a newline is basically impossible for a test runner to pass in. Also, it feels fragile somehow to dip in and out of the trio loop patching the signal handler and peeking forKeyboardInterrupt
.