⏱️ Execution Counter (nhk)
Generate Exactly N Images, Then Stop — Execution Counter (nhk)
- input
- output
- status
- current_count
- should_stop
Execution Counter (nhk) counts how many times the workflow runs and stops the queue when it hits your target. Set target_count to 50, queue up an infinite-ish batch, and the whole thing halts after exactly 50 executions. It's a batch limiter that lives inside the graph instead of in your head.
This is the "generate exactly N images then stop" tool, and it's more useful than it sounds. ComfyUI's queue lets you enqueue a workflow a hundred times, but there's no built-in "stop after 50" - you either babysit the counter or enqueue precisely and hope nothing fails and needs a rerun. A counter node puts the limit in the workflow itself, so it works whether you enqueued 10 runs or 10,000, and it survives the occasional failure-and-rerun that would wreck a manual count.
How it works
The node keeps a running count in memory (thread-safe, with a lock - it's designed to not trip over itself). On each execution it increments the counter and checks against target_count:
- Below target: passes your
inputthrough, reportscurrent_count/target_count. - Exactly at target: that's the final run - it marks
should_stoptrue, says "WILL STOP AFTER THIS," and passes through. - Past target: it hard-stops by raising a
RuntimeError, which halts the workflow. That's a deliberate, blunt mechanism - an exception ends execution for real, rather than hoping the UI notices a flag.
IS_CHANGED returns NaN so the node re-executes every single queue run; without that, ComfyUI would cache it as unchanged and the count would never advance. The reset_counter boolean zeroes the count back, so you can reuse the same workflow for a new batch without reloading.
Inputs and outputs
input- pass-through value (any type).target_count- INT, 1–10000, default 100. Stop after this many executions.reset_counter- boolean, default false. Reset the count to 0.
Outputs:
output- your input, passed through.status- STRING, human-readable progress like "Running - Count: 3/100".current_count- INT, executions so far.should_stop- BOOLEAN, true when this run is the final one.
Installing it
Part of ComfyUI-nhknodes:
cd ComfyUI/custom_nodes && git clone https://github.com/Enashka/ComfyUI-nhknodes
restart, or "NHK Nodes" from ComfyUI Manager. No extra deps.
The honest caveats
Two things to know before you trust an overnight batch to it. First, the stop mechanism is "raise an exception past the target," which means the workflow stops with an error trace in the console - not a graceful "queue drained" ending. That's by design (it's the only reliable halt), but it means your final image of the run may come from the second-to-last execution, and you'll see a scary-looking error line. Second, the count is in-memory: restart ComfyUI and the counter resets. For a batch you want to resume across restarts, you'll want to track the count externally or just accept the reset. Within a single sitting, though, this is the cleanest "N images and done" you'll get without writing your own queue logic.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| input | * | Pass-through input (any type) | |
| target_count | INT | 1001–10000 | Stop queue after this many executions |
| reset_counter | BOOLEAN | false | Reset counter back to 0 |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| output | * | — |
| status | STRING | — |
| current_count | INT | — |
| should_stop | BOOLEAN | — |