Skip to content

Commit 47e8195

Browse files
committed
Wait only for esc_timeout seconds in unix_console.get_event() and windows_console.get_event()
1 parent 420863b commit 47e8195

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/_pyrepl/unix_console.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@ def get_event(self, block: bool = True) -> Event | None:
558558
return None
559559

560560
while self.event_queue.empty():
561+
if self.event_queue.pending():
562+
if not self.wait(timeout=self.event_queue.esc_timeout):
563+
# Timed out waiting for the rest of a sequence: flush the
564+
# pending prefix as a complete key (e.g. a lone ESC).
565+
self.event_queue.flush()
566+
continue
561567
while True:
562568
try:
563569
self.push_char(self.__read(1))

Lib/_pyrepl/windows_console.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,12 @@ def get_event(self, block: bool = True) -> Event | None:
572572
return None
573573

574574
while self.event_queue.empty():
575+
if self.event_queue.pending():
576+
# Timed out waiting for the rest of a sequence: flush the
577+
# pending prefix as a complete key (e.g. a lone ESC).
578+
if not self.wait_for_event(self.event_queue.esc_timeout * 1000):
579+
self.event_queue.flush()
580+
continue
575581
rec = self._read_input()
576582
if rec is None:
577583
return None

0 commit comments

Comments
 (0)