Skip to content

Instantly share code, notes, and snippets.

@Cologler
Last active May 26, 2022 12:33
Show Gist options
  • Save Cologler/036d834fbf04bc335000145dc896a240 to your computer and use it in GitHub Desktop.
Save Cologler/036d834fbf04bc335000145dc896a240 to your computer and use it in GitHub Desktop.
wait with keyboard Interrupt support
# -*- coding: utf-8 -*-
#
# Copyright (c) 2022~2999 - Cologler <skyoflw@gmail.com>
# ----------
#
# ----------
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