class_docstr: Helper class for raising errors on low memory.
  
  This presents a much cleaner error message to users than what would happen
  if we actually ran out of memory.
  
  The monitor tries to use the cgroup memory limit and usage if it is set
  and available so that it is more reasonable inside containers. Otherwise,
  it uses `psutil` to check the memory usage.
  
  The environment variable `RAY_MEMORY_MONITOR_ERROR_THRESHOLD` can be used
  to overwrite the default error_threshold setting.
  
  Used by test only. For production code use memory_monitor.cc
class_docstr_tok: ["Helper","class","for","raising","errors","on","low","memory",".","This","presents","a","much","cleaner","error","message","to","users","than","what","would","happen","if","we","actually","ran","out","of","memory",".","The","monitor","tries","to","use","the","cgroup","memory","limit","and","usage","if","it","is","set","and","available","so","that","it","is","more","reasonable","inside","containers",".","Otherwise",",","it","uses","`","psutil","`","to","check","the","memory","usage",".","The","environment","variable","`","RAY_MEMORY_MONITOR_ERROR_THRESHOLD","`","can","be","used","to","overwrite","the","default","error_threshold","setting",".","Used","by","test","only",".","For","production","code","use","memory_monitor.cc"]
code: def __init__(self, error_threshold=0.95, check_interval=1):
      # Note: it takes ~50us to check the memory usage through psutil, so
      # throttle this check at most once a second or so.
      self.check_interval = check_interval
      self.last_checked = 0
      try:
          self.error_threshold = float(
              os.getenv("RAY_MEMORY_MONITOR_ERROR_THRESHOLD")
          )
      except (ValueError, TypeError):
          self.error_threshold = error_threshold
      # Try to read the cgroup memory limit if it is available.
      try:
          with open(
              "/sys/fs/cgroup/memory/memory.limit_in_bytes", "rb"
          ) as f:
              self.cgroup_memory_limit_gb = int(f.read()) / (1024**3)
      except IOError:
          self.cgroup_memory_limit_gb = sys.maxsize / (1024**3)
      if not psutil:
          logger.warn(
              "WARNING: Not monitoring node memory since `psutil` "
              "is not installed. Install this with "
              "`pip install psutil` to enable "
              "debugging of memory-related crashes."
          )
      self.disabled = (
          "RAY_DEBUG_DISABLE_MEMORY_MONITOR" in os.environ
          or "RAY_DISABLE_MEMORY_MONITOR" in os.environ
      )
  
file_path: ray/python/ray/_private/memory_monitor.py
imports: import logging
  import os
  import platform
  import sys
  import time
  import ray
  import psutil
label_desc: Use image node_id 1 to create a new MemoryMonitor object  with example: obj = MemoryMonitor(error_threshold, check_interval)