def test_TensorBoard_across_invocations(self):
        """Regression test for summary writer resource use-after-free."""
        model = self._get_model()
        x, y = np.ones((10, 10, 10, 1)), np.ones((10, 1))
        logdir, train_dir, validation_dir = self._get_log_dirs()
        tb_cbk = callbacks.TensorBoard(logdir)

        for _ in (1, 2):
            model.fit(
                x,
                y,
                batch_size=2,
                epochs=2,
                validation_data=(x, y),
                callbacks=[tb_cbk],
            )

        summary_file = list_summaries(logdir)
        self.assertEqual(
            summary_file.scalars,
            {
                _ObservedSummary(logdir=train_dir, tag="epoch_loss"),
                _ObservedSummary(logdir=validation_dir, tag="epoch_loss"),
                _ObservedSummary(logdir=train_dir, tag="epoch_learning_rate"),
                _ObservedSummary(
                    logdir=validation_dir,
                    tag="evaluation_loss_vs_iterations",
                ),
            },
        )
Regression test for summary writer resource use-after-free.
keras/src/callbacks/tensorboard_test.py