def write_to_textfile(path, registry):
tmppath = '<STR_LIT>' % (path, os.getpid(), threading.current_thread().ident)<EOL>with open(tmppath, '<STR_LIT:wb>') as f:<EOL><INDENT>f.write(generate_latest(registry))<EOL><DEDENT>os.rename(tmppath, path)<EOL>
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.