def clear_handlers(logger):
    """
    Clear all handlers from logger

    Parameters
    ----------
    logger : logging.logger
        Logger to remove all handlers from

    Returns
    -------
    logger : logging.logger
        Logger with all handlers removed
    """
    handlers = logger.handlers.copy()
    for handler in handlers:
        # Copied from `logging.shutdown`.
        try:
            handler.acquire()
            handler.flush()
            handler.close()
        except (OSError, ValueError):
            pass
        finally:
            handler.release()

        logger.removeHandler(handler)

    logger.handlers.clear()

    return logger