code: def get_free_gpus(max_procs=0):
      """
      Checks the number of processes running on your GPUs.
  
      Parameters
      ----------
      max_procs : int
          Maximum number of procs allowed to run on a gpu for it to be considered
          'available'
  
      Returns
      -------
      availabilities : list(bool)
          List of length N for an N-gpu system. The nth value will be true, if the
          nth gpu had at most max_procs processes running on it. Set to 0 to look
          for gpus with no procs on it.
  
      Note
      ----
      If function can't query the driver will return an empty list rather than raise an
      Exception.
      """
      # Try connect with NVIDIA drivers
      logger = logging.getLogger(__name__)
      try:
          py3nvml.nvmlInit()
      except:
          str_ = """Couldn't connect to nvml drivers. Check they are installed correctly."""
          warnings.warn(str_, RuntimeWarning)
          logger.warning(str_)
          return []
  
      num_gpus = py3nvml.nvmlDeviceGetCount()
      gpu_free = [False] * num_gpus
      for i in range(num_gpus):
          try:
              h = py3nvml.nvmlDeviceGetHandleByIndex(i)
          except:
              continue
  
          procs = try_get_info(
              py3nvml.nvmlDeviceGetComputeRunningProcesses,
              h,
              ["something"],
          )
          if len(procs) <= max_procs:
              gpu_free[i] = True
  
      py3nvml.nvmlShutdown()
      return gpu_free
  
file_path: py3nvml/py3nvml/utils.py
imports: from __future__ import absolute_import
  from __future__ import print_function
  from __future__ import division
  import logging
  import os
  import warnings
  from py3nvml import py3nvml
label_desc: Use image node_id 3 for calling a global function with example usage: get_free_gpus(max_procs) and returns: gpu_free, list