mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
better sleep
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
import platform
|
import platform
|
||||||
|
|
||||||
from asyncio import sleep as asleep
|
from asyncio import sleep as asyncio_sleep, get_running_loop
|
||||||
from time import monotonic, perf_counter
|
from time import monotonic, perf_counter, sleep as time_sleep
|
||||||
|
|
||||||
|
|
||||||
PLATFORM = platform.system()
|
PLATFORM = platform.system()
|
||||||
WINDOWS = PLATFORM == "Windows"
|
WINDOWS = PLATFORM == "Windows"
|
||||||
@@ -23,9 +24,7 @@ if WINDOWS:
|
|||||||
Args:
|
Args:
|
||||||
sleep_for (float): Seconds to sleep for.
|
sleep_for (float): Seconds to sleep for.
|
||||||
"""
|
"""
|
||||||
start = time()
|
await get_running_loop().run_in_executor(None, time_sleep, sleep_for)
|
||||||
while time() - start < sleep_for - 1 / 1000:
|
|
||||||
await asleep(0)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
sleep = asleep
|
sleep = asyncio_sleep
|
||||||
|
|||||||
Reference in New Issue
Block a user