code: def testRunInBackgroundRepeatedlyThreeTimes(self):
      state = {"counter": 0}
  
      def run_three_times():
          state["counter"] += 1
          if state["counter"] == 3:
              raise StopIteration()
  
      OriginalThread = threading.Thread
      with mock.patch.object(
          threading,
          "Thread",
          # Use a non-daemon thread for testing. A non-daemon thread
          # will block the test process from exiting if not terminated
          # properly. Here the thread is expected to be terminated by the
          # `StopIteration` raised by `run_three_times()`.
          lambda target, daemon: OriginalThread(
              target=target, daemon=False
          ),
      ):
          (
              interrupt_event,
              thread,
          ) = debug_data_multiplexer.run_repeatedly_in_background(
              run_three_times,
              None,  # `interval_sec is None` means indefinite wait()
          )
          interrupt_event.set()
          time.sleep(0.05)
          interrupt_event.set()
          time.sleep(0.05)
          interrupt_event.set()
      thread.join()
      self.assertEqual(state["counter"], 3)
  
file_path: tensorboard/tensorboard/plugins/debugger_v2/debug_data_multiplexer_test.py
imports: import threading
  import time
  import tensorflow
  from tensorboard.plugins.debugger_v2 import debug_data_multiplexer
label_desc: Use image node_id 1 for calling the RunInBackgroundRepeatedlyTest obj's underlying member method code with example usage: obj.testRunInBackgroundRepeatedlyThreeTimes() without return types