code: def _periodically_flush_profile_events(self):
          
          # Note(rkn): This is run on a background thread in the driver. It uses
          # the raylet client. This should be ok because it doesn't read
          # from the raylet client and we have the GIL here. However,
          # if either of those things changes, then we could run into issues.
          while True:
              # Sleep for 1 second. This will be interrupted if
              # self.threads_stopped is set.
              self.threads_stopped.wait(timeout=1)
  
              # Exit if we received a signal that we should stop.
              if self.threads_stopped.is_set():
                  return
  
              self.flush_profile_data()
docs: Drivers run this as a thread to flush profile data in the
          background.