Last active
May 26, 2022 12:33
-
-
Save Cologler/036d834fbf04bc335000145dc896a240 to your computer and use it in GitHub Desktop.
wait with keyboard Interrupt support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# Copyright (c) 2022~2999 - Cologler <[email protected]> | |
# ---------- | |
# | |
# ---------- | |
from time import monotonic as _time | |
def iwait(wait, timeout=None, *, interval=0.1): | |
''' | |
a wait function that support keyboard Interrupt. | |
''' | |
if timeout is None: | |
while not wait(interval): pass | |
else: | |
end = _time() + timeout | |
while (_time() < end) and (not wait(interval)): pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment