better sleep

This commit is contained in:
Will McGugan
2022-12-29 20:41:14 +00:00
parent 85582a4093
commit 7fa289a332

View File

@@ -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