import functools
import time


def _retry(fun, *, n, sleep_s):
    """Retries a function up to N times until it returns truthy value"""
    assert n

    @functools.wraps(fun)
    def wrapper(*args, **kwargs):
        res = None
        for _ in range(n):
            res = fun(*args, **kwargs)
            if res:
                return res
            time.sleep(sleep_s)

        return res

    return wrapper