Skip to content

Commit 0ec1a4a

Browse files
committed
fix post
1 parent d9a229f commit 0ec1a4a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docs/blog/posts/better-sleep-on-windows.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ I spent some time optimizing Textual on Windows recently, and discovered somethi
1212

1313
<!-- more -->
1414

15-
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.
15+
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.
1616

1717
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.
1818

@@ -33,7 +33,7 @@ This lack of accuracy in the timer meant that timer events were created at a far
3333
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%:
3434

3535
```python
36-
from time import sleep
36+
from time import sleep as time_sleep
3737
from asyncio import get_running_loop
3838

3939
async def sleep(sleep_for: float) -> None:
@@ -44,7 +44,9 @@ async def sleep(sleep_for: float) -> None:
4444
Args:
4545
sleep_for (float): Seconds to sleep for.
4646
"""
47-
await get_running_loop().run_in_executor(None, sleep, sleep_for)
47+
print("sleep")
48+
await get_running_loop().run_in_executor(None, time_sleep, sleep_for)
49+
4850
```
4951

5052
That is a drop-in replacement for sleep on Windows. With it, Textual runs a *lot* smoother. Easily on par with macOS and Linux.

src/textual/_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
async def sleep(sleep_for: float) -> None:
2020
"""An asyncio sleep.
2121
22-
On Windows this achieves a better granularity than asyncio.sleep
22+
On Windows this achieves a better granularity that asyncio.sleep
2323
2424
Args:
2525
sleep_for (float): Seconds to sleep for.

0 commit comments

Comments
 (0)