old_contents: import atexit
  import time
  
  import pynvml
  import prometheus_client
  
  from .stats import NvidiaStats
  from .prometheus_metrics import build_metrics
  
  if __name__ == '__main__':
      try:
          pynvml.nvmlInit()
          atexit.register(pynvml.nvmlShutdown)
          stats = NvidiaStats()
          for device_index in range(0, stats.device_count()):
              print("Device name", stats.device_name(device_index))
              print("GPU temperature", stats.gpu_temp(device_index))
              print("Fan speed", stats.device_fan_speed(device_index))
              print("Power usage", stats.device_power_usage(device_index))
              print("Power limit", stats.device_power_limit(device_index))
              print("Free memory", stats.device_free_memory(device_index))
              print("Used memory", stats.device_used_memory(device_index))
              print("Total memory", stats.device_total_memory(device_index))
              print("Graphics processes", stats.graphics_processes(device_index))
              print("Compute processes", stats.compute_processes(device_index))
  
          build_metrics()
          prometheus_client.start_http_server(9200)
          while True:
              time.sleep(10)	
  
      except pynvml.NVMLError, err:
          print("NVML error: %s" % err)
  
new_contents: import atexit
  import time
  
  import pynvml
  from prometheus_client import make_wsgi_app
  from wsgiref.simple_server import make_server
  
  from .stats import NvidiaStats
  from .prometheus_metrics import build_metrics
  
  if __name__ == '__main__':
      try:
          pynvml.nvmlInit()
          atexit.register(pynvml.nvmlShutdown)
  
          build_metrics()
          app = make_wsgi_app()
          httpd = make_server('', 9200, app)
          httpd.serve_forever()
      except pynvml.NVMLError, err:
          print("NVML error: %s" % err)
  
subject: use wsgi to serve in foreground