code: def start_scheduler(
      logdir,
      addr,
      port,
      ssh_username,
      ssh_port,
      ssh_private_key,
      remote_python=None,
  ):
      cmd = "{python} -m distributed.cli.dask_scheduler --port {port}".format(
          python=remote_python or sys.executable, port=port
      )
  
      # Optionally re-direct stdout and stderr to a logfile
      if logdir is not None:
          cmd = f"mkdir -p {logdir} && {cmd}"
          cmd += "&> {logdir}/dask_scheduler_{addr}:{port}.log".format(
              addr=addr, port=port, logdir=logdir
          )
  
      # Format output labels we can prepend to each line of output, and create
      # a 'status' key to keep track of jobs that terminate prematurely.
      label = f"{bcolors.BOLD}scheduler {addr}:{port}{bcolors.ENDC}"
  
      # Create a command dictionary, which contains everything we need to run and
      # interact with this command.
      input_queue = Queue()
      output_queue = Queue()
      cmd_dict = {
          "cmd": cmd,
          "label": label,
          "address": addr,
          "port": port,
          "input_queue": input_queue,
          "output_queue": output_queue,
          "ssh_username": ssh_username,
          "ssh_port": ssh_port,
          "ssh_private_key": ssh_private_key,
      }
  
      # Start the thread
      thread = Thread(target=async_ssh, args=[cmd_dict])
      thread.daemon = True
      thread.start()
  
      return merge(cmd_dict, {"thread": thread})
  
imports: from __future__ import annotations
  import logging
  import os
  import socket
  import sys
  import traceback
  import warnings
  from queue import Queue
  from threading import Thread
  from time import sleep
  from tlz import merge
  from tornado import gen
  from distributed.metrics import time
label_desc: Use image node_id 2 for calling a global function with example usage: start_scheduler(logdir, addr, port, ssh_username, ssh_port, ssh_private_key, remote_python) and returns: merge