code: def single_node_env(num_gpus=1, worker_index=-1, nodes=[]):
      """Setup environment variables for Hadoop compatibility and GPU allocation"""
      # ensure expanded CLASSPATH w/o glob characters (required for Spark 2.1 + JNI)
      if (
          "HADOOP_PREFIX" in os.environ
          and "TFOS_CLASSPATH_UPDATED" not in os.environ
      ):
          classpath = os.environ["CLASSPATH"]
          hadoop_path = os.path.join(
              os.environ["HADOOP_PREFIX"], "bin", "hadoop"
          )
          hadoop_classpath = subprocess.check_output(
              [hadoop_path, "classpath", "--glob"]
          ).decode()
          os.environ["CLASSPATH"] = (
              classpath + os.pathsep + hadoop_classpath
          )
          os.environ["TFOS_CLASSPATH_UPDATED"] = "1"
  
      if gpu_info.is_gpu_available() and num_gpus > 0:
          # reserve GPU(s), if requested
          if worker_index >= 0 and nodes and len(nodes) > 0:
              # compute my index relative to other nodes on the same host, if known
              my_addr = nodes[worker_index]
              my_host = my_addr.split(":")[0]
              local_peers = [n for n in nodes if n.startswith(my_host)]
              my_index = local_peers.index(my_addr)
          else:
              # otherwise, just use global worker index
              my_index = worker_index
  
          gpus_to_use = gpu_info.get_gpus(num_gpus, my_index)
          logger.info("Using gpu(s): {0}".format(gpus_to_use))
          os.environ["CUDA_VISIBLE_DEVICES"] = gpus_to_use
      else:
          # CPU
          logger.info("Using CPU")
          os.environ["CUDA_VISIBLE_DEVICES"] = ""
  
file_path: TensorFlowOnSpark/tensorflowonspark/util.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import nested_scopes
  from __future__ import print_function
  import logging
  import os
  import socket
  import subprocess
  import errno
  from socket import error
  from .None import gpu_info
label_desc: Use image node_id 1 for calling a global function with example usage: single_node_env(num_gpus, worker_index, nodes) without return types