def refresh_client_and_session(self):
        """
        Refreshes the databricks client and spark session if the session_id has been invalidated due to expiration of temporary credentials.
        If the client is running within an interactive Databricks notebook environment, the spark session is not terminated.
        """

        _logger.info("Refreshing Databricks client and Spark session due to session expiration.")
        self.client = get_default_databricks_workspace_client(profile=self.profile)
        if not _is_in_databricks_notebook_environment():
            self.stop_spark_session()
        self.initialize_spark_session()

        Refreshes the databricks client and spark session if the session_id has been invalidated due to expiration of temporary credentials.
        If the client is running within an interactive Databricks notebook environment, the spark session is not terminated.
        
ai/core/src/unitycatalog/ai/core/databricks.py