def repeater(call, args=None, kwargs=None, retries=4):
    """
    repeat call x-times: docker API is just awesome

    :param call: function
    :param args: tuple, args for function
    :param kwargs: dict, kwargs for function
    :param retries: int, how many times we try?
    :return: response of the call
    """
    args = args or ()
    kwargs = kwargs or {}
    t = 1.0
    for x in range(retries):
        try:
            return call(*args, **kwargs)
        except APIError as ex:
            logger.error("query #%d: docker returned an error: %r", x, ex)
        except Exception as ex:
            # this may be pretty bad
            log_last_traceback()
            logger.error("query #%d: generic error: %r", x, ex)
        t *= 2
        time.sleep(t)