Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-130328: further speedup of pasting in new REPL on Windows by reading in chunks#132889
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
0a38c2e05d26ffcad6bfb3d1da664098e3da64f4c4937b6bdbba26c997946643c0cae9b6ea2528fa84d15b055f1a7ebeedFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -64,6 +64,8 @@ def __init__(self, err: int | None, descr: str | None = None) -> None: | ||||||||||||||||||||
| if TYPE_CHECKING: | ||||||||||||||||||||
| from typing import IO | ||||||||||||||||||||
| INPUT_BUFFER_LEN = 10 * 1024 | ||||||||||||||||||||
| # Virtual-Key Codes: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes | ||||||||||||||||||||
| VK_MAP: dict[int, str] ={ | ||||||||||||||||||||
| 0x23: "end", # VK_END | ||||||||||||||||||||
| @@ -165,6 +167,10 @@ def __init__( | ||||||||||||||||||||
| # Console I/O is redirected, fallback... | ||||||||||||||||||||
| self.out = None | ||||||||||||||||||||
| self.input_buffer = (INPUT_RECORD * INPUT_BUFFER_LEN)() | ||||||||||||||||||||
| self.input_buffer_pos = 0 | ||||||||||||||||||||
| self.input_buffer_count = 0 | ||||||||||||||||||||
| def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None: | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| Refresh the console screen. | ||||||||||||||||||||
| @@ -415,16 +421,27 @@ def _getscrollbacksize(self) -> int: | ||||||||||||||||||||
| return info.srWindow.Bottom # type: ignore[no-any-return] | ||||||||||||||||||||
| def more_in_buffer(self) -> bool: | ||||||||||||||||||||
| return self.input_buffer_pos < self.input_buffer_count - 1 | ||||||||||||||||||||
| def _read_input(self, block: bool = True) -> INPUT_RECORD | None: | ||||||||||||||||||||
| if not block and not self.wait(timeout=0): | ||||||||||||||||||||
| return None | ||||||||||||||||||||
| rec = INPUT_RECORD() | ||||||||||||||||||||
| if self.more_in_buffer(): | ||||||||||||||||||||
| self.input_buffer_pos += 1 | ||||||||||||||||||||
| return self.input_buffer[self.input_buffer_pos] | ||||||||||||||||||||
| # read next chunk | ||||||||||||||||||||
| self.input_buffer_pos = 0 | ||||||||||||||||||||
| self.input_buffer_count = 0 | ||||||||||||||||||||
| read = DWORD() | ||||||||||||||||||||
| if not ReadConsoleInput(InHandle, rec, 1, read): | ||||||||||||||||||||
| if not ReadConsoleInput(InHandle, self.input_buffer, INPUT_BUFFER_LEN, read): | ||||||||||||||||||||
| raise WinError(GetLastError()) | ||||||||||||||||||||
| return rec | ||||||||||||||||||||
| self.input_buffer_count = read.value | ||||||||||||||||||||
| return self.input_buffer[0] | ||||||||||||||||||||
| def get_event(self, block: bool = True) -> Event | None: | ||||||||||||||||||||
| """Return an Event instance. Returns None if |block| is false | ||||||||||||||||||||
| @@ -521,9 +538,15 @@ def forgetinput(self) -> None: | ||||||||||||||||||||
| def getpending(self) -> Event: | ||||||||||||||||||||
| """Return the characters that have been typed but not yet | ||||||||||||||||||||
| processed.""" | ||||||||||||||||||||
| return Event("key", "", b"") | ||||||||||||||||||||
| e = Event("key", "", b"") | ||||||||||||||||||||
| while not self.event_queue.empty(): | ||||||||||||||||||||
| e2 = self.event_queue.get() | ||||||||||||||||||||
| e.data += e2.data | ||||||||||||||||||||
| def wait(self, timeout: float | None) -> bool: | ||||||||||||||||||||
| return e | ||||||||||||||||||||
| def wait_for_event(self, timeout: float | None) -> bool: | ||||||||||||||||||||
| """Wait for an event.""" | ||||||||||||||||||||
| if timeout is None: | ||||||||||||||||||||
| timeout = INFINITE | ||||||||||||||||||||
| @@ -536,6 +559,16 @@ def wait(self, timeout: float | None) -> bool: | ||||||||||||||||||||
| return False | ||||||||||||||||||||
| return True | ||||||||||||||||||||
| def wait(self, timeout: float | None = None) -> bool: | ||||||||||||||||||||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Full in sync with cpython/Lib/_pyrepl/unix_console.py Lines 419 to 427 in e1c09ff
| ||||||||||||||||||||
| """ | ||||||||||||||||||||
| Wait for events on the console. | ||||||||||||||||||||
| """ | ||||||||||||||||||||
| return ( | ||||||||||||||||||||
| not self.event_queue.empty() | ||||||||||||||||||||
| or self.more_in_buffer() | ||||||||||||||||||||
| or self.wait_for_event(timeout) | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| def repaint(self) -> None: | ||||||||||||||||||||
| raise NotImplementedError("No repaint support") | ||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
I've just copy-pasted this from
cpython/Lib/_pyrepl/unix_console.py
Lines 536 to 555 in e1c09ff
and dropped the reading of the next chunk, since IMHO this does not fit the doc string.
mypy fires here
and is indeed correct. Have to dig in why we do not see this in case of
unix_console.py...