code: def print_to(
      self,
      fp,
      *,
      with_colors=True,  # deprecated arg
      show_cmd=False,
      show_full_cmd=False,
      no_processes=False,
      show_user=False,
      show_pid=False,
      show_fan_speed=None,
      show_codec="",
      show_power=None,
      gpuname_width=None,
      eol_char=os.linesep,
      term=None,
  ):
      if term is None:
          term = Terminal(stream=sys.stdout)
  
      # color settings
      colors = {}
  
      def _conditional(
          cond_fn, true_value, false_value, error_value=term.bold_black
      ):
          try:
              return cond_fn() and true_value or false_value
          except Exception:  # pylint: disable=broad-exception-caught
              return error_value
  
      _ENC_THRESHOLD = 50
  
      colors["C0"] = term.normal
      colors["C1"] = term.cyan
      colors["CName"] = _conditional(
          lambda: self.available, term.blue, term.red
      )
      colors["CTemp"] = _conditional(
          lambda: self.temperature < 50, term.red, term.bold_red
      )
      colors["FSpeed"] = _conditional(
          lambda: self.fan_speed < 30, term.cyan, term.bold_cyan
      )
      colors["CMemU"] = _conditional(
          lambda: self.available, term.bold_yellow, term.bold_black
      )
      colors["CMemT"] = _conditional(
          lambda: self.available, term.yellow, term.bold_black
      )
      colors["CMemP"] = term.yellow
      colors["CCPUMemU"] = term.yellow
      colors["CUser"] = term.bold_black  # gray
      colors["CUtil"] = _conditional(
          lambda: self.utilization < 30, term.green, term.bold_green
      )
      colors["CUtilEnc"] = _conditional(
          lambda: self.utilization_enc < _ENC_THRESHOLD,
          term.green,
          term.bold_green,
      )
      colors["CUtilDec"] = _conditional(
          lambda: self.utilization_dec < _ENC_THRESHOLD,
          term.green,
          term.bold_green,
      )
      colors["CCPUUtil"] = term.green
      colors["CPowU"] = _conditional(
          lambda: (
              self.power_limit is not None
              and float(self.power_draw) / self.power_limit < 0.4
          ),  # type: ignore
          term.magenta,
          term.bold_magenta,
      )
      colors["CPowL"] = term.magenta
      colors["CCmd"] = term.color(24)  # a bit dark
  
      if not with_colors:
          for k in list(colors.keys()):
              colors[k] = ""
  
      def _repr(v, none_value: Any = "??"):
          return none_value if v is None else v
  
      # build one-line display information
      # we want power use optional, but if deserves being grouped with
      # temperature and utilization
  
      reps = []
  
      def _write(*args, color=None, end=""):
          args = [str(x) for x in args]
          if color:
              # pylint: disable-next=consider-using-get
              if color in colors:
                  color = colors[color]
              args = [color] + args + [term.normal]
          if end:
              args.append(end)
          reps.extend(args)
  
      def rjustify(x, size):
          return f"{x:>{size}}"
  
      # Null-safe property accessor like self.xxxx,
      # but fall backs to '?' for None or missing values
      class SafePropertyAccessor:
          def __init__(self, obj):
              self.obj = obj
  
          def __getattr__(self, name):  # type: ignore
              try:
                  v = getattr(self.obj, name)
                  return v if v is not None else "??"
              except TypeError:  # possibly int(None), etc.
                  return "??"
  
      safe_self = cast(GPUStat, SafePropertyAccessor(self))
  
      _write(f"[{self.index}]", color=term.cyan)
      _write(" ")
  
      if gpuname_width is None or gpuname_width != 0:
          gpuname_width = gpuname_width or DEFAULT_GPUNAME_WIDTH
          _write(
              f"{util.shorten_left(self.name, width=gpuname_width, placeholder='…'):{gpuname_width}}",
              color="CName",
          )
          _write(" |")
  
      _write(
          rjustify(safe_self.temperature, 3),
          "°C",
          color="CTemp",
          end=", ",
      )
  
      if show_fan_speed:
          _write(
              rjustify(safe_self.fan_speed, 3),
              " %",
              color="FSpeed",
              end=", ",
          )
  
      _write(rjustify(safe_self.utilization, 3), " %", color="CUtil")
  
      if show_codec:
          _write(" (")
          _sep = ""
          if "enc" in show_codec:
              _write("E: ", color=term.bold)
              _write(
                  rjustify(safe_self.utilization_enc, 3),
                  " %",
                  color="CUtilEnc",
              )
              _sep = "  "  # TODO comma?
          if "dec" in show_codec:
              _write(_sep, "D: ", color=term.bold)
              _write(
                  rjustify(safe_self.utilization_dec, 3),
                  " %",
                  color="CUtilDec",
              )
          _write(")")
  
      if show_power:
          _write(",  ")
          _write(rjustify(safe_self.power_draw, 3), color="CPowU")
          if show_power is True or "limit" in show_power:
              _write(" / ")
              _write(
                  rjustify(safe_self.power_limit, 3),
                  " W",
                  color="CPowL",
              )
  
      # Memory
      _write(" | ")
      _write(rjustify(safe_self.memory_used, 5), color="CMemU")
      _write(" / ")
      _write(rjustify(safe_self.memory_total, 5), color="CMemT")
      _write(" MB")
  
      # Add " |" only if processes information is to be added.
      if not no_processes:
          _write(" |")
  
      def process_repr(p: ProcessInfo):
          r = ""
          if not show_cmd or show_user:
              r += "{CUser}{}{C0}".format(
                  _repr(p["username"], "--"), **colors
              )
          if show_cmd:
              if r:
                  r += ":"
              r += "{C1}{}{C0}".format(
                  _repr(p.get("command", p["pid"]), "--"), **colors
              )
  
          if show_pid:
              r += "/%s" % _repr(p["pid"], "--")
          r += "({CMemP}{}M{C0})".format(
              _repr(p["gpu_memory_usage"], "?"), **colors
          )
          return r
  
      def full_process_info(p: ProcessInfo):
          r = "{C0} ├─ {:>6} ".format(_repr(p["pid"], "--"), **colors)
          r += "{C0}({CCPUUtil}{:4.0f}%{C0}, {CCPUMemU}{:>6}{C0})".format(
              _repr(p["cpu_percent"], "--"),
              util.bytes2human(_repr(p["cpu_memory_usage"], 0)),
              **colors,
          )  # type: ignore
          full_command_pretty = util.prettify_commandline(
              p["full_command"], colors["C1"], colors["CCmd"]
          )
          r += "{C0}: {CCmd}{}{C0}".format(
              _repr(full_command_pretty, "?"), **colors
          )
          return r
  
      processes = self.entry["processes"]
      full_processes = []
      if processes is None and not no_processes:
          # None (not available)
          _write(" ", "(", NOT_SUPPORTED, ")")
      elif not no_processes:
          for p in processes or []:
              _write(" ", process_repr(p))
              if show_full_cmd:
                  full_processes.append(eol_char + full_process_info(p))
      if show_full_cmd and full_processes:
          full_processes[-1] = full_processes[-1].replace("├", "└", 1)
          _write("".join(full_processes))
  
      fp.write("".join(reps))
      return fp
  
imports: import functools
  from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Optional, Sequence, Union, cast
  import json
  import locale
  import os.path
  import platform
  import sys
  import time
  from datetime import datetime
  from io import StringIO
  import psutil
  from blessed import Terminal
  from gpustat import util
  from gpustat import nvml
  from gpustat.nvml import pynvml
  from gpustat.nvml import check_driver_nvml_version
label_desc: Use image node_id 21 for calling the GPUStat obj's underlying member method code with example usage: obj.print_to(fp) and returns: fp, unknown, x, r, r, unknown, error_value, unknown, str