code: def on_event(
      event,
      func,
      args=(),
      stop=None,
      check_stop_interval_s=1.0,
      daemon=True,
      silent=False,
  ):
      """
      Executes the given function in a separate thread when event is set.
      That threat can be stopped by setting the optional stop event.
      The stop event is check regularly every check_interval_seconds.
      Exceptions will silently be swallowed when silent is True.
  
      :param event: event that triggers func
      :type event: threading.Event
      :param func: function to trigger
      :param args: function arguments
      :param stop: event to stop thread
      :type stop: threading.Event
      :param check_stop_interval_s: interval in seconds to check the stop event
      :type check_stop_interval_s: float
      :param daemon: event thread is a daemon thread if set to True, otherwise stop event must be given
      :param silent: swallows exceptions raised by target silently
      :return: thread
      """
      if event is None:
          raise ValueError("Event must not be None")
  
      if not isinstance(args, tuple):
          raise ValueError(
              "args must be a tuple, not {}, for a single argument use (arg,)".format(
                  type(args)
              )
          )
  
      if stop is None:
          if not daemon:
              raise ValueError(
                  "Stop event must be given for non-daemon event thread"
              )
  
          def fn():
              event.wait()
              func(*args)
  
      else:
  
          def fn():
              while not event.is_set() and not stop.is_set():
                  event.wait(timeout=check_stop_interval_s)
              if not stop.is_set():
                  func(*args)
  
      return in_thread(fn, daemon=daemon, silent=silent)
  
imports: import queue
  import threading
label_desc: Use image node_id 3 for calling a global function with example usage: on_event(event, func, args, stop, check_stop_interval_s, daemon, silent) and returns: in_thread