Skip to content

Commit 7fa289a

Browse files
committed
better sleep
1 parent 85582a4 commit 7fa289a

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/textual/_time.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import platform
22

3-
from asyncio import sleep as asleep
4-
from time import monotonic, perf_counter
3+
from asyncio import sleep as asyncio_sleep, get_running_loop
4+
from time import monotonic, perf_counter, sleep as time_sleep
5+
56

67
PLATFORM = platform.system()
78
WINDOWS = PLATFORM == "Windows"
@@ -23,9 +24,7 @@ async def sleep(sleep_for: float) -> None:
2324
Args:
2425
sleep_for (float): Seconds to sleep for.
2526
"""
26-
start = time()
27-
while time() - start < sleep_for - 1 / 1000:
28-
await asleep(0)
27+
await get_running_loop().run_in_executor(None, time_sleep, sleep_for)
2928

3029
else:
31-
sleep = asleep
30+
sleep = asyncio_sleep

0 commit comments

Comments
 (0)