code: def start_master(
      port,
      gpu_cluster,
      cpu_num,
      gpu,
      monitor_port,
      debug,
      log_server_port_range,
  ):
      if cpu_num is not None:
          assert (
              cpu_num >= 0
          ), "cpu_num should be greater than or equal to 0."
  
      if not gpu_cluster:
          gpu = ""
      else:
          cpu_num = 0
  
      if debug:
          os.environ["DEBUG"] = "True"
  
      if not is_port_available(port):
          raise Exception(
              "The master address localhost:{} is already in use.".format(
                  port
              )
          )
  
      if monitor_port and not is_port_available(monitor_port):
          raise Exception(
              "The input monitor port localhost:{} is already in use.".format(
                  monitor_port
              )
          )
  
      cpu_num = (
          int(cpu_num)
          if cpu_num is not None
          else multiprocessing.cpu_count()
      )
      start_file = __file__.replace("scripts.pyc", "start.py")
      start_file = start_file.replace("scripts.py", "start.py")
      monitor_file = __file__.replace("scripts.pyc", "monitor.py")
      monitor_file = monitor_file.replace("scripts.py", "monitor.py")
  
      if monitor_port is None:
          monitor_port = str(int(port) + 100)
          if not is_port_available(monitor_port):
              monitor_port = get_free_tcp_port()
  
      start, end = parse_port_range(log_server_port_range)
      log_server_port = get_port_from_range(start, end)
      while log_server_port == monitor_port or log_server_port == port:
          log_server_port = get_port_from_range(start, end)
  
      master_command = XPARL_PYTHON + [
          start_file,
          "--name",
          "master",
          "--port",
          port,
          "--monitor_port",
          monitor_port,
      ]
      if gpu_cluster:
          master_command.append("--gpu_cluster")
      worker_command = XPARL_PYTHON + [
          start_file,
          "--name",
          "worker",
          "--address",
          "localhost:" + str(port),
          "--cpu_num",
          str(cpu_num),
          "--log_server_port",
          str(log_server_port),
          "--gpu",
          gpu,
      ]
      monitor_command = XPARL_PYTHON + [
          monitor_file,
          "--monitor_port",
          str(monitor_port),
          "--address",
          "localhost:" + str(port),
      ]
      if gpu_cluster:
          monitor_command.append("--gpu_cluster")
  
      FNULL = open(os.devnull, "w")
  
      # Redirect the output to DEVNULL to solve the warning log.
      _ = subprocess.Popen(master_command, stdout=FNULL, close_fds=True)
  
      if cpu_num > 0 or gpu:
          # Sleep 1s for master ready
          time.sleep(1)
          _ = subprocess.Popen(
              worker_command, stdout=FNULL, close_fds=True
          )
  
      if _IS_WINDOWS:
          # TODO(@zenghsh3) redirecting stdout of monitor subprocess to FNULL will cause occasional failure
          tmp_file = tempfile.TemporaryFile()
          _ = subprocess.Popen(
              monitor_command, stdout=tmp_file, close_fds=True
          )
          tmp_file.close()
      else:
          _ = subprocess.Popen(
              monitor_command, stdout=FNULL, close_fds=True
          )
      FNULL.close()
  
      if cpu_num > 0 or gpu:
          monitor_info = """
              # The Parl cluster is started at localhost:{}.
  
              # A local worker with {} CPUs is connected to the cluster.    
  
              # Starting the cluster monitor...""".format(
              port,
              cpu_num,
          )
      else:
          monitor_info = """
              # The Parl cluster is started at localhost:{}.
  
              # Starting the cluster monitor...""".format(
              port
          )
      click.echo(monitor_info)
  
      # check if monitor is started
      monitor_is_started = False
      if _IS_WINDOWS:
          cmd = r"""wmic process where "commandline like '%remote\\monitor.py --monitor_port {} --address localhost:{}%'" get commandline /format:list | findstr /V wmic | findstr CommandLine=""".format(
              monitor_port, port
          )
      else:
          cmd = r"ps -ef | grep -v grep | grep remote/monitor.py\ --monitor_port\ {}\ --address\ localhost:{}".format(
              monitor_port, port
          )
      for i in range(3):
          check_monitor_is_started = os.popen(cmd).read()
          if len(check_monitor_is_started) > 0:
              monitor_is_started = True
              break
          time.sleep(3)
  
      master_ip = get_ip_address()
      if monitor_is_started:
          start_info = """
          ## If you want to check cluster status, please view:
  
              http://{}:{}
  
          or call:
  
              xparl status""".format(
              master_ip, monitor_port
          )
      else:
          start_info = "# Fail to start the cluster monitor."
  
      monitor_info = """
          {}
  
          ## If you want to add more CPU resources, please call:
  
              xparl connect --address {}:{}
  
          ## If you want to add more GPU resources, please call:
  
              xparl connect --address {}:{} --gpu 0,1,2,...
  
          ## If you want to shutdown the cluster, please call:
  
              xparl stop        
          """.format(
          start_info, master_ip, port, master_ip, port
      )
      click.echo(monitor_info)
  
      if cpu_num > 0 or gpu:
          check_log_server_started(master_ip, log_server_port)
  
imports: import click
  import locale
  import multiprocessing
  import os
  import random
  import re
  import requests
  import subprocess
  import sys
  import time
  import threading
  import tempfile
  import warnings
  import zmq
  from multiprocessing import Process
  from parl.utils import _IS_WINDOWS, get_free_tcp_port, get_ip_address, get_port_from_range, is_port_available, kill_process, to_str
  from parl.remote.remote_constants import STATUS_TAG
  from parl.remote.utils import XPARL_PYTHON
label_desc: Use image node_id 5 for calling a global function with example usage: start_master(port, gpu_cluster, cpu_num, gpu, monitor_port, debug, log_server_port_range) without return types