import time


def retry(predicate_task, timeout_sec=30, every=0.05, msg='Timed out retrying'):
    """
    Repeat task every `interval` until it returns a truthy value or times out.
    """
    begin = time.monotonic()
    threshold = begin + timeout_sec
    while True:
        res = predicate_task()
        if res:
            return res
        elif time.monotonic() < threshold:
            time.sleep(every)
        else:
            raise TimeoutError(msg)