Nodes/tri3d-comfyui-nodes/Wait and read text file, optional control from text v5.1.0
ComfyUI Node

Wait and read text file, optional control from text v5.1.0

Make ComfyUI wait for an external process, then read its file

By TRI3D-LC·Created 3 years ago·Updated about a year ago· 27
Wait and read text file, optional control from text v5.1.0
    • text from file
    absolute_filenameimage.txt
    text

    ComfyUI runs in one process, but your pipeline doesn't have to. Every so often you want a node to sit and wait for something outside ComfyUI to finish - a Python script, a web service, another tool writing a file - and then pick up the result. That's exactly what Wait and read text file, optional control from text does: it blocks until a file appears at an absolute path, reads its contents as a string, and deletes the file.

    It's from the tri3d-comfyui-nodes pack (TRI3D-LC, v5.1.0), and it's an OUTPUT_NODE - the terminal of a branch. Its sibling tri3d_SaveText_absolute (same pack, same category) writes the file on the other end, and this node is the reader. The pack's own segmentation nodes shell out to external Python processes, so this is how the author coordinates with them: the external tool writes a "done" file, and this node waits for it.

    How it works

    The whole mechanism is a polling loop:

    while not os.path.exists(absolute_filename):
        time.sleep(0.1)
    res = open(absolute_filename, "r").read()
    os.unlink(absolute_filename)
    

    Three behaviors worth internalizing: it polls every 0.1s until the file exists, it returns the file's contents as a STRING, and it deletes the file after reading. That last one means it's strictly one-shot - the next run starts clean, and you can't accidentally re-read stale data.

    The inputs that matter

    • absolute_filename (STRING, default image.txt) - the absolute path to the file to read. Absolute, not relative to ComfyUI's output folder.
    • text (optional, multiline) - this is the interesting one. It does nothing to the output; it exists purely so you can wire an upstream string in and force ComfyUI's graph ordering. If the thing that should run before the wait isn't otherwise connected to this node, feed its output in here so the graph won't run the wait first. The tooltip says it directly: "Text to provide order when necessary (to wait on done file)."

    Output is a single STRING named text from file, which you then wire into anything that consumes text - a prompt, a StringContains check, a filename.

    Install

    ComfyUI Manager → search tri3d-comfyui-nodes, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes
    

    Restart ComfyUI. Nothing to download - os and time only.

    Gotchas

    The big one: there is no timeout. If the external process never writes the file, this node spins forever and your queue hangs with zero feedback. Make sure whatever you're waiting on is reliable, or wrap it in something that always writes a file. Second: it deletes the file it reads, so if you needed that file for anything else, copy it first. And because it's an output node, ComfyUI treats it as a graph endpoint - run it as the last step of a branch unless you wire the ordering carefully through that optional text input. It's a slightly terrifying little node until you trust the process on the other end; once you do, it's the cleanest cross-process handshake in the pack.

    Categorytext

    Inputs (2)

    NameTypeDefaultDescription
    absolute_filenameSTRINGimage.txtThe absolute path to the file to read.
    textoptSTRINGText to provide order when necessary (to wait on done file).

    Outputs (1)

    NameTypeDescription
    text from fileSTRING