code: def print_gpustat(*, id=None, json=False, debug=False, **kwargs):
      """Display the GPU query results into standard output."""
      try:
          gpu_stats = GPUStatCollection.new_query(debug=debug, id=id)
      except Exception as e:
          sys.stderr.write(
              "Error on querying NVIDIA devices. "
              "Use --debug flag to see more details.\n"
          )
          term = Terminal(stream=sys.stderr)
          sys.stderr.write(term.red(str(e)) + "\n")
  
          if debug:
              sys.stderr.write("\n")
              try:
                  import traceback
  
                  traceback.print_exc(file=sys.stderr)
              except Exception:
                  # NVMLError can't be processed by traceback:
                  #   https://bugs.python.org/issue28603
                  # as a workaround, simply re-throw the exception
                  raise e
  
          sys.stderr.flush()
          sys.exit(1)
  
      if json:
          gpu_stats.print_json(sys.stdout)
      else:
          gpu_stats.print_formatted(sys.stdout, **kwargs)
  
file_path: gpustat/gpustat/cli.py
imports: import os
  import sys
  import time
  from contextlib import suppress
  from blessed import Terminal
  from gpustat import __version__
  from gpustat.core import GPUStatCollection
label_desc: Use image node_id 3 for calling a global function with example usage: print_gpustat() without return types