Skip to content

Commit

Permalink
Switch to chunking Windows terminal sequences based on buffer size
Browse files Browse the repository at this point in the history
First we tested this by splitting the output by lines; that worked but it
could be faster. So now we're going to take the problematic buffer
size (32KiB), assume a reasonable worst case of every character heading out
being 3 bytes in size, and chunking the output based on that.

In other words, experiment for #2548 take two.
  • Loading branch information
davep committed Nov 7, 2023
1 parent 357268e commit 6293fe1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2527,9 +2527,19 @@ def _display(self, screen: Screen, renderable: RenderableType | None) -> None:
self._handle_exception(error)
else:
if WINDOWS:
# Combat a problem with Python on Windows.
#
# https://github.com/Textualize/textual/issues/2548
# https://github.com/python/cpython/issues/82052
CHUNK_SIZE = 8192
write = self._driver.write
for line in terminal_sequence.split("\n"):
write(line)
for chunk in (
terminal_sequence[offset : offset + CHUNK_SIZE]
for offset in range(
0, len(terminal_sequence), CHUNK_SIZE
)
):
write(chunk)
else:
self._driver.write(terminal_sequence)
finally:
Expand Down

0 comments on commit 6293fe1

Please sign in to comment.