我想知道在给定的超时时间内是否有足够的方法或模块等待条件(返回bool的函数)?实施例
def wait_for_condition(condition, timeout, interval) :
# implementation
# return True if the condition met in given timeout, else return False
提前致谢!
答案 0 :(得分:2)
我只想自己动手,这看起来很简单:
def wait_until(condition, interval=0.1, timeout=1, *args):
start = time.time()
while not condition(*args) and time.time() - start < timeout:
time.sleep(interval)