code: def launch_with_gnome_terminal(
      commands_to_launch, use_tabs=False
  ) -> Union[
      worker_manager.WorkerManager, worker_manager_v2.WorkerManager
  ]:
      """Launch commands given as CommandToLaunch tuples with gnome-terminal.
  
      Args:
        commands_to_launch: An iterable of `CommandToLaunch` namedtuples.
        use_tabs: Whether or not to run each command in a gnome tab (instead of a
          window)
  
      Returns:
        Worker manager that can be used to wait for a program execution to finish.
      """
      if lp_flags.LP_WORKER_MANAGER_V2.value:
          commands_to_launch = copy.deepcopy(commands_to_launch)
          for command_to_launch in commands_to_launch:
              command_to_launch.command_as_list.append(
                  "--lp_worker_manager_v2"
              )
      # The new server-client architecture of gnome-terminal removes several
      # extremely useful features. Relevant ones here are
      #   * The ability to launch commands as new tabs.
      #   * The ability to destroy gnome terminal windows from the command line.
      # While there is nothing we can do about the former, there's a workaround
      # for the latter. We start a new gnome-terminal-server and launch all
      # windows belonging to this launchpad session in this server. To clean up,
      # we can just kill the server and all windows get closed. This has the
      # additional benefit that windows are grouped together when switching between
      # applications with alt-tab.
      if not feature_testing.has_gnome_terminal():
          raise ValueError(
              "`gnome-terminal` is not available, "
              "please choose another way to launch."
          )
      # Check if we can find the gnome-terminal-server.
      gnome_terminal_server_path = find_gnome_terminal_server()
      if not gnome_terminal_server_path:
          raise ValueError(
              "gnome-terminal-server is not present on your system but it is required "
              "to launch locally with gnome-terminal. Searched: {}".format(
                  GNOME_TERMINAL_SERVER_PATHS
              )
          )
      # Start session.
      timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
      # app-ids must be character only. Turn numbers in timestep to characters.
      timestamp = "".join(["abcdefghij"[int(c)] for c in timestamp])
      app_id = "launchpad.locallaunch.{}".format(timestamp)
  
      def preexec_fn():
          # Prevents SIGINT from killing gnome-terminal-server too early
          signal.signal(signal.SIGINT, signal.SIG_IGN)
  
      server_process = subprocess.Popen(
          [
              gnome_terminal_server_path,
              "--app-id",
              app_id,
              "--name",
              app_id,
              "--class",
              app_id,
          ],
          env=os.environ,
          preexec_fn=preexec_fn,
      )
      if lp_flags.LP_WORKER_MANAGER_V2.value:
          # process_tree_depth=2 because the interpreter will be at level 2 of
          # gnome-terminal -> bash -> interpreter.
          manager = worker_manager_v2.WorkerManager(
              handle_sigterm=True,
              kill_all_upon_sigint=True,
              process_tree_depth=2,
          )
      else:
          manager = worker_manager.WorkerManager()
      atexit.register(manager.wait)
      manager.register_existing_process("gnome", server_process.pid)
      if use_tabs:
          _launch_in_tabs(commands_to_launch, app_id)
      else:
          _launch_in_windows(commands_to_launch, app_id)
  
      return manager
  
imports: import atexit
  import copy
  import datetime
  import os
  import shlex
  import signal
  import stat
  import subprocess
  import tempfile
  import time
  from typing import Union
  from launchpad import flags
  from launchpad.launch import worker_manager
  from launchpad.launch import worker_manager_v2
  from launchpad.launch.run_locally import feature_testing
label_desc: Use image node_id 5 for calling a global function with example usage: launch_with_gnome_terminal(commands_to_launch, use_tabs) and returns: manager