code: def launch_gateway():
      # type: () -> JavaGateway
      """
      launch jvm gateway
      """
      if is_launch_gateway_disabled():
          raise Exception(
              "It's launching the PythonGatewayServer during Python UDF execution "
              "which is unexpected. It usually happens when the job codes are "
              "in the top level of the Python script file and are not enclosed in a "
              "`if name == 'main'` statement."
          )
  
      args = [
          "-c",
          "org.apache.flink.client.python.PythonGatewayServer",
      ]
  
      submit_args = os.environ.get("SUBMIT_ARGS", "local")
      args += shlex.split(submit_args)
  
      # Create a temporary directory where the gateway server should write the connection information.
      conn_info_dir = tempfile.mkdtemp()
      try:
          fd, conn_info_file = tempfile.mkstemp(dir=conn_info_dir)
          os.close(fd)
          os.unlink(conn_info_file)
  
          _find_flink_home()
  
          env = dict(os.environ)
          env["_PYFLINK_CONN_INFO_PATH"] = conn_info_file
  
          p = launch_gateway_server_process(env, args)
  
          while not p.poll() and not os.path.isfile(conn_info_file):
              time.sleep(0.1)
  
          if not os.path.isfile(conn_info_file):
              stderr_info = p.stderr.read().decode("utf-8")
              raise RuntimeError(
                  "Java gateway process exited before sending its port number.\nStderr:\n"
                  + stderr_info
              )
  
          with open(conn_info_file, "rb") as info:
              gateway_port = struct.unpack("!I", info.read(4))[0]
      finally:
          shutil.rmtree(conn_info_dir)
  
      # Connect to the gateway
      gateway = JavaGateway(
          gateway_parameters=GatewayParameters(
              port=gateway_port, auto_convert=True
          ),
          callback_server_parameters=CallbackServerParameters(
              port=0, daemonize=True, daemonize_connections=True
          ),
      )
  
      return gateway
  
imports: import importlib
  import os
  import shlex
  import shutil
  import struct
  import tempfile
  import time
  from logging import WARN
  from threading import RLock
  from py4j.java_gateway import java_import, logger, JavaGateway, GatewayParameters, CallbackServerParameters
  from pyflink.find_flink_home import _find_flink_home
  from pyflink.pyflink_gateway_server import launch_gateway_server_process
  from pyflink.util.exceptions import install_exception_handler, install_py4j_hooks
label_desc: Use image node_id 3 for calling a global function with example usage: launch_gateway() and returns: gateway