def METHOD_NAME(condition, msg=None, timeout=5, sleep=.05):
    import time
    curtime = time.time()
    while True:
        if condition():
            break
        if time.time() - curtime > timeout:
            error_msg = 'Condition not reached in %s seconds' % (timeout,)
            if msg is not None:
                error_msg += '\n'
                if callable(msg):
                    error_msg += msg()
                else:
                    error_msg += str(msg)
            raise AssertionError('Timeout: %s' % (error_msg,))
        time.sleep(sleep)