def METHOD_NAME(func, path, exc_info):
    max_attempts = 15
    retry_interval = 0.1
    effective_ids = os.access in os.supports_effective_ids
    existing_files = glob(f"{path}/*")
    if not os.access(path, os.W_OK, effective_ids=effective_ids):
        os.chmod(path, stat.S_IWUSR)
        try:
            return func(path)
        except FileNotFoundError:
            return
    else:
        # For some weird reason we do have rights to remove the dir,
        # let's try again a few times more slowly (maybe a previous OS call
        # returned to the python interpreter but the files were not completely
        # removed yet?)
        for i in range(max_attempts):
            try:
                return rmtree(path)
            except FileNotFoundError:
                return
            except OSError:
                sleep((i + 1) * retry_interval)
    logging.critical(
        "Something went wrong when removing %s. Contents:\n%s",
        path,
        pformat(existing_files),  # weirdly this is usually empty
        exc_info=exc_info,
    )
    (type_, value, traceback) = exc_info
    raise type_(value).with_traceback(traceback)