code: def write_to_textfile(path, registry):
      
      tmppath = '%s.%s.%s' % (path, os.getpid(), threading.current_thread().ident)
      with open(tmppath, 'wb') as f:
          f.write(generate_latest(registry))
      # rename(2) is atomic.
      os.rename(tmppath, path)
docs: Write metrics to the given path.
  
      This is intended for use with the Node exporter textfile collector.
      The path must end in .prom for the textfile collector to process it.