Files
ComfyUI-Dataset-Gates/gates/gate_bus.py
T
Ethanfel b50718f7fb fix: image gate reacts to ComfyUI Interrupt
GateBus.wait() only checked the gate's own Stop flag, so pressing ComfyUI's
Interrupt left the image gate blocked. Add should_cancel to wait() (mirroring
wait_payload) and pass mm.processing_interrupted from gate.py, matching the
text gate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 14:17:20 +02:00

60 lines
1.8 KiB
Python

"""Blocking choice bus for the Image Gate node. Stdlib only — no comfy/torch."""
import time
class GateCancelled(Exception):
pass
class GateBus:
messages = {} # node_id(str) -> chosen int (1-based)
masks = {} # node_id(str) -> PNG bytes
payloads = {} # node_id(str) -> arbitrary payload (e.g., edited text)
cancelled = False
@classmethod
def arm(cls, node_id):
cls.messages.pop(str(node_id), None)
cls.masks.pop(str(node_id), None)
cls.payloads.pop(str(node_id), None)
cls.cancelled = False
@classmethod
def put(cls, node_id, message):
if message == "__cancel__":
cls.cancelled = True
else:
cls.messages[str(node_id)] = int(message)
@classmethod
def wait(cls, node_id, period=0.1, should_cancel=None):
sid = str(node_id)
while sid not in cls.messages:
if cls.cancelled or (should_cancel is not None and should_cancel()):
cls.cancelled = False
raise GateCancelled()
time.sleep(period)
return cls.messages.pop(sid)
@classmethod
def put_mask(cls, node_id, data):
cls.masks[str(node_id)] = data
@classmethod
def pop_mask(cls, node_id):
return cls.masks.pop(str(node_id), None)
@classmethod
def put_payload(cls, node_id, value):
cls.payloads[str(node_id)] = value
@classmethod
def wait_payload(cls, node_id, period=0.1, should_cancel=None):
sid = str(node_id)
while sid not in cls.payloads:
if cls.cancelled or (should_cancel is not None and should_cancel()):
cls.cancelled = False
raise GateCancelled()
time.sleep(period)
return cls.payloads.pop(sid)