From 4b92985b2bd47b180544c326c8a84bd2f9496366 Mon Sep 17 00:00:00 2001 From: Lysandros Nikolaou Date: Tue, 4 Jun 2024 23:22:28 +0200 Subject: [PATCH] gh-119553: Fix console when pressing Ctrl-C within a multiline block (GH-120075) (cherry picked from commit 69b3e8ea569faabccd74036e3d0e5ec7c0c62a20) Co-authored-by: Lysandros Nikolaou --- Lib/_pyrepl/commands.py | 2 ++ Lib/_pyrepl/simple_interact.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/_pyrepl/commands.py b/Lib/_pyrepl/commands.py index e94e8c25d379c1..6bffed1bfe9327 100644 --- a/Lib/_pyrepl/commands.py +++ b/Lib/_pyrepl/commands.py @@ -216,11 +216,13 @@ def do(self) -> None: import signal self.reader.console.finish() + self.reader.finish() os.kill(os.getpid(), signal.SIGINT) class ctrl_c(Command): def do(self) -> None: + self.reader.console.finish() self.reader.finish() raise KeyboardInterrupt diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py index 256bbc7c6d7626..2e5698eb131684 100644 --- a/Lib/_pyrepl/simple_interact.py +++ b/Lib/_pyrepl/simple_interact.py @@ -149,7 +149,7 @@ def more_lines(unicodetext: str) -> bool: assert not more input_n += 1 except KeyboardInterrupt: - console.write("\nKeyboardInterrupt\n") + console.write("KeyboardInterrupt\n") console.resetbuffer() except MemoryError: console.write("\nMemoryError\n")