def retry_if(predicate):
    """
    Create a predicate compatible with ``with_retry``
    which will retry if the raised exception satisfies the given predicate.

    :param predicate: A one-argument callable which will be called with the
        raised exception instance only.  It should return ``True`` if a retry
        should be attempted, ``False`` otherwise.
    """
    def should_retry(exc_type, value, traceback):
        if predicate(value):
            return None
        raise exc_type, value, traceback
    return should_retry