Skip to content

Commit 231fa21

Browse files
committed
fix win sleep
1 parent 29e5f76 commit 231fa21

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/textual/_win_sleep.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
INFINITE = 0xFFFFFFFF
1010
WAIT_FAILED = 0xFFFFFFFF
11+
CREATE_WAITABLE_TIMER_MANUAL_RESET = 0x00000001
1112
CREATE_WAITABLE_TIMER_HIGH_RESOLUTION = 0x00000002
1213

1314

@@ -22,13 +23,14 @@ def sleep(sleep_for: float) -> None:
2223
handle = kernel32.CreateWaitableTimerExW(
2324
None,
2425
None,
25-
CREATE_WAITABLE_TIMER_HIGH_RESOLUTION,
26+
CREATE_WAITABLE_TIMER_HIGH_RESOLUTION | CREATE_WAITABLE_TIMER_MANUAL_RESET,
2627
0x1F0003,
2728
)
2829
if not handle:
2930
time_sleep(sleep_for)
3031
return
3132

33+
sleep_for -= 1 / 1000
3234
if not kernel32.SetWaitableTimer(
3335
handle,
3436
ctypes.byref(LARGE_INTEGER(int(sleep_for * -10_000_000))),
@@ -38,8 +40,10 @@ def sleep(sleep_for: float) -> None:
3840
0,
3941
):
4042
kernel32.CloseHandle(handle)
43+
print("error")
4144
time_sleep(sleep_for)
4245
return
4346

44-
kernel32.WaitForSingleObject(handle, INFINITE)
47+
if kernel32.WaitForSingleObject(handle, INFINITE) == WAIT_FAILED:
48+
time_sleep(sleep_for)
4549
kernel32.CloseHandle(handle)

0 commit comments

Comments
 (0)