diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-09-06 20:25:19 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-06 20:25:19 (GMT) |
| commit | 5c3078d6e597c7e50b3b0da37f493e2dfca17a6a (patch) | |
| tree | c8f16cbf540fee5b7527d51b3b9ff7ed9c8b065e /Lib/_pyrepl/unix_console.py | |
| parent | 66b15381f187f00f0fd91575f9f11e14bfddeeca (diff) | |
| download | cpython-5c3078d6e597c7e50b3b0da37f493e2dfca17a6a.zip cpython-5c3078d6e597c7e50b3b0da37f493e2dfca17a6a.tar.gz cpython-5c3078d6e597c7e50b3b0da37f493e2dfca17a6a.tar.bz2 | |
[3.13] gh-120221: Support KeyboardInterrupt in asyncio REPL (GH-123795) (#123799)
This switches the main pyrepl event loop to always be non-blocking so that it
can listen to incoming interruptions from other threads.
This also resolves invalid display of exceptions from other threads
(gh-123178).
This also fixes freezes with pasting and an active input hook.
(cherry picked from commit 033510e11dff742d9626b9fd895925ac77f566f1)
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/_pyrepl/unix_console.py')
| -rw-r--r-- | Lib/_pyrepl/unix_console.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/_pyrepl/unix_console.py b/Lib/_pyrepl/unix_console.py index bdea285..09b5094 100644 --- a/Lib/_pyrepl/unix_console.py +++ b/Lib/_pyrepl/unix_console.py @@ -199,8 +199,14 @@ class UnixConsole(Console): self.event_queue = EventQueue(self.input_fd, self.encoding) self.cursor_visible = 1 + def more_in_buffer(self) -> bool: + return bool( + self.input_buffer + and self.input_buffer_pos < len(self.input_buffer) + ) + def __read(self, n: int) -> bytes: - if not self.input_buffer or self.input_buffer_pos >= len(self.input_buffer): + if not self.more_in_buffer(): self.input_buffer = os.read(self.input_fd, 10000) ret = self.input_buffer[self.input_buffer_pos : self.input_buffer_pos + n] @@ -393,6 +399,7 @@ class UnixConsole(Console): """ if not block and not self.wait(timeout=0): return None + while self.event_queue.empty(): while True: try: @@ -413,7 +420,11 @@ class UnixConsole(Console): """ Wait for events on the console. """ - return bool(self.pollob.poll(timeout)) + return ( + not self.event_queue.empty() + or self.more_in_buffer() + or bool(self.pollob.poll(timeout)) + ) def set_cursor_vis(self, visible): """ |
