Skip to content

Commit 380f411

Browse files
authored
Merge branch 'main' into pythongh-119842
2 parents 1b37860 + 010ea93 commit 380f411

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎Lib/_pyrepl/commands.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def do(self) -> None:
221221

222222
class ctrl_c(Command):
223223
def do(self) -> None:
224+
self.reader.finish()
224225
raise KeyboardInterrupt
225226

226227

‎Lib/test/test_pyrepl/support.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def handle_all_events(
7575
reader.handle1()
7676
except StopIteration:
7777
pass
78+
except KeyboardInterrupt:
79+
pass
7880
return reader, console
7981

8082

‎Lib/test/test_pyrepl/test_reader.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ def _prepare_console(events):
196196

197197
self.assertEqual(len(input_hook.mock_calls), 4)
198198

199+
def test_keyboard_interrupt_clears_screen(self):
200+
namespace = {"itertools": itertools}
201+
code = "import itertools\nitertools."
202+
events = itertools.chain(code_to_events(code), [
203+
Event(evt='key', data='\t', raw=bytearray(b'\t')), # Two tabs for completion
204+
Event(evt='key', data='\t', raw=bytearray(b'\t')),
205+
Event(evt='key', data='\x03', raw=bytearray(b'\x03')), # Ctrl-C
206+
])
207+
208+
completing_reader = functools.partial(
209+
prepare_reader,
210+
readline_completer=rlcompleter.Completer(namespace).complete
211+
)
212+
reader, _ = handle_all_events(events, prepare_reader=completing_reader)
213+
self.assertEqual(reader.calc_screen(), code.split("\n"))
214+
199215
def test_prompt_length(self):
200216
# Handles simple ASCII prompt
201217
ps1 = ">>> "

‎Lib/test/test_signal.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def handler(signum, frame):
698698
@unittest.skipUnless(hasattr(os, "pipe"), "requires os.pipe()")
699699
class SiginterruptTest(unittest.TestCase):
700700

701-
def readpipe_interrupted(self, interrupt):
701+
def readpipe_interrupted(self, interrupt, timeout=support.SHORT_TIMEOUT):
702702
"""Perform a read during which a signal will arrive. Return True if the
703703
read is interrupted by the signal and raises an exception. Return False
704704
if it returns normally.
@@ -746,7 +746,7 @@ def handler(signum, frame):
746746
# wait until the child process is loaded and has started
747747
first_line = process.stdout.readline()
748748

749-
stdout, stderr = process.communicate(timeout=support.SHORT_TIMEOUT)
749+
stdout, stderr = process.communicate(timeout=timeout)
750750
except subprocess.TimeoutExpired:
751751
process.kill()
752752
return False
@@ -777,7 +777,7 @@ def test_siginterrupt_off(self):
777777
# If a signal handler is installed and siginterrupt is called with
778778
# a false value for the second argument, when that signal arrives, it
779779
# does not interrupt a syscall that's in progress.
780-
interrupted = self.readpipe_interrupted(False)
780+
interrupted = self.readpipe_interrupted(False, timeout=2)
781781
self.assertFalse(interrupted)
782782

783783

0 commit comments

Comments
 (0)