code: def _make_spark_thread(
      spark_context,
      spark_job_group,
      driver,
      result_queue,
      settings,
      use_gloo,
      is_elastic,
  ):
      """Creates `settings.num_proc` Spark tasks in a parallel thread."""
  
      def run_spark():
          """Creates `settings.num_proc` Spark tasks, each executing `_task_fn` and waits for them to terminate."""
          try:
              spark_context.setJobGroup(
                  spark_job_group,
                  "Horovod Spark Run",
                  interruptOnCancel=True,
              )
              procs = spark_context.range(
                  0,
                  numSlices=settings.max_num_proc
                  if settings.elastic
                  else settings.num_proc,
              )
              # We assume that folks caring about security will enable Spark RPC encryption,
              # thus ensuring that key that is passed here remains secret.
              mapper = _make_mapper(
                  driver.addresses(), settings, use_gloo, is_elastic
              )
              result = procs.mapPartitionsWithIndex(mapper).collect()
              result_queue.put(result)
          except:
              driver.notify_spark_job_failed()
              raise
  
      spark_thread = in_thread(target=run_spark, daemon=False)
      return spark_thread
  
imports: import logging
  import os
  import platform
  import queue
  import sys
  import time
  import warnings
  import pyspark
  from horovod.common.util import gloo_built
  from horovod.runner.util.threads import in_thread
  from horovod.spark.common.util import host_hash
  from horovod.spark.task import task_service
  from horovod.spark.gloo_run import gloo_run, gloo_run_elastic
  from horovod.spark.mpi_run import mpi_run
  from horovod.runner.launch import is_gloo_used, run_controller
  from horovod.runner.common.util import timeout, secret
  from horovod.runner.common.util import settings
  from horovod.runner.elastic import settings
  from horovod.spark.driver import driver_service, host_discovery, job_id
label_desc: Use image node_id 3 for calling a global function with example usage: _make_spark_thread(spark_context, spark_job_group, driver, result_queue, settings, use_gloo, is_elastic) and returns: spark_thread