From 0ec1a4a5d668fb95db495bb7782366984fbf23b0 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Fri, 30 Dec 2022 12:27:08 +0000 Subject: [PATCH] fix post --- docs/blog/posts/better-sleep-on-windows.md | 8 +++++--- src/textual/_time.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/blog/posts/better-sleep-on-windows.md b/docs/blog/posts/better-sleep-on-windows.md index d1c1842ad..19ddf8cb4 100644 --- a/docs/blog/posts/better-sleep-on-windows.md +++ b/docs/blog/posts/better-sleep-on-windows.md @@ -12,7 +12,7 @@ I spent some time optimizing Textual on Windows recently, and discovered somethi -Animation, scrolling, and fading had always been unsatisfactory on Windows. Textual was usable, but the lag when scrolling made it a little unpleasant to use. On macOS and Linux, scrolling is fast enough that it feels close to a native app, and not something running in a terminal. Yet the Windows experience never improved, even as Textual got faster with each release. +Animation, scrolling, and fading had always been unsatisfactory on Windows. Textual was usable, but the lag when scrolling made apps feel far less snappy that other platforms. On macOS and Linux, scrolling is fast enough that it feels close to a native app, not something running in a terminal. Yet the Windows experience never improved, even as Textual got faster with each release. I had chalked this up to Windows Terminal being slow to render updates. After all, the classic Windows terminal was (and still is) glacially slow. Perhaps Microsoft just weren't focusing on performance. @@ -33,7 +33,7 @@ This lack of accuracy in the timer meant that timer events were created at a far Once I had figured that out, I needed an alternative to `asyncio.sleep` for Textual's Timer class. And I found one. The following version of `sleep` is accurate to well within 1%: ```python -from time import sleep +from time import sleep as time_sleep from asyncio import get_running_loop async def sleep(sleep_for: float) -> None: @@ -44,7 +44,9 @@ async def sleep(sleep_for: float) -> None: Args: sleep_for (float): Seconds to sleep for. """ - await get_running_loop().run_in_executor(None, sleep, sleep_for) + print("sleep") + await get_running_loop().run_in_executor(None, time_sleep, sleep_for) + ``` That is a drop-in replacement for sleep on Windows. With it, Textual runs a *lot* smoother. Easily on par with macOS and Linux. diff --git a/src/textual/_time.py b/src/textual/_time.py index 3343697a0..f33246946 100644 --- a/src/textual/_time.py +++ b/src/textual/_time.py @@ -19,7 +19,7 @@ if WINDOWS: async def sleep(sleep_for: float) -> None: """An asyncio sleep. - On Windows this achieves a better granularity than asyncio.sleep + On Windows this achieves a better granularity that asyncio.sleep Args: sleep_for (float): Seconds to sleep for.