-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0a38c2e
fix WindowsConsole.wait()
chris-eibl 05d26ff
blurb it
chris-eibl cad6bfb
fix timeout=None
chris-eibl 3d1da66
fix mypy for ctypes.get_last_error
chris-eibl 4098e3d
fix return value of wait() and use it in _read_input()
chris-eibl a64f4c4
read in chunks
chris-eibl 937b6bd
fix missing return in getpending
chris-eibl bba26c9
use self.paste_mode instead of self.in_bracketed_paste
chris-eibl 9794664
Merge branch 'fix_wait' into read_chunked
chris-eibl 3c0cae9
Revert "use self.paste_mode instead of self.in_bracketed_paste"
chris-eibl b6ea252
Merge branch 'fix_wait' into read_chunked
chris-eibl 8fa84d1
Merge branch 'main' into read_chunked
chris-eibl 5b055f1
remove copying of the raw member of Event, because
chris-eibl a7ebeed
Merge branch 'read_chunked' of https://github.com/chris-eibl/cpython …
chris-eibl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||||||||||||||||||||
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") | ||||||||||||||||||||
|
||||||||||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
...