code: def run(self):
          
  
          if self._generator:
              try:
                  gen = self._routine(*self._worker_args, **self._worker_kwargs)
  
                  while True:
                      if self._stop_condition.is_set():
                          return
  
                      self._running.set()
  
                      next(gen)
  
                      for _i in range(0, self._wait_count):
                          if self._stop_condition.is_set():
                              return
                          time.sleep(self._wait)
  
              except StopIteration:
                  pass
              except Exception:
                  print("Exception occurred in background worker thread")
                  traceback.print_exc()
          else:
              try:
                  while True:
                      if self._stop_condition.is_set():
                          break
  
                      self._running.set()
  
                      self._routine(*self._worker_args, **self._worker_kwargs)
  
                      # Wait for the desired interval, checking if we should exit
                      for _i in range(0, self._wait_count):
                          if self._stop_condition.is_set():
                              return
  
                          time.sleep(self._wait)
              except Exception:
                  print("Exception occurred in background worker thread")
                  traceback.print_exc()
docs: The target routine called to start thread activity.
  
          If the thread is created with a generator function, this iterates
          the generator and checks for a stop condition between each iteration.
  
          If the thread is created with a normal function, that function is called
          in a loop with the stop condition checked between each invocation.