From 300dd7795e1b3eb1af28eb3e726f89dc83e2af1f Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 29 Mar 2025 16:35:53 +1100 Subject: [PATCH] logging --- image_filter.py | 17 ++++++++++++----- js/popup.js | 6 +++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/image_filter.py b/image_filter.py index 3e0524e..ff0b488 100644 --- a/image_filter.py +++ b/image_filter.py @@ -27,22 +27,23 @@ async def cg_image_filter_message(request): post = await request.post() response = post.get("response") if (Message.data is None or (Message.data != CANCEL and response not in SPECIALS)): - Message.data = response + Message.setdata(response, "response") else: print(f"Ignoring response {response} as current response is {Message.data}") return web.json_response({}) def wait(secs, uid): - Message.data = None + Message.setdata(None, "start of wait") end_time = time.monotonic() + secs while(time.monotonic() < end_time and Message.data is None): throw_exception_if_processing_interrupted() PromptServer.instance.send_sync("cg-image-filter-images", {"tick": int(end_time - time.monotonic()), "uid": uid}) time.sleep(0.2) response = Message.data + Message.setdata(None, "read response") if response is None: PromptServer.instance.send_sync("cg-image-filter-images", {"timeout": True, "uid": uid}) - Message.data = None + return response def send_with_resend(payload, timeout, uid): @@ -50,7 +51,8 @@ def send_with_resend(payload, timeout, uid): while response in SPECIALS: PromptServer.instance.send_sync("cg-image-filter-images", payload) response = wait(timeout, uid) - if response == CANCEL: raise InterruptProcessingException() + if response == CANCEL: + raise InterruptProcessingException() return response def mask_to_image(mask:torch.Tensor): @@ -58,6 +60,10 @@ def mask_to_image(mask:torch.Tensor): class Message: data:str = None + @classmethod + def setdata(cls, v, comment): + print(f"Message.data set to {v} (${comment})") + cls.data = v HIDDEN = { "prompt": "PROMPT", @@ -206,5 +212,6 @@ class MaskImageFilter(PreviewImage, LoadImage): except FileNotFoundError: pass - if if_no_mask == 'cancel': raise InterruptProcessingException() + if if_no_mask == 'cancel': + raise InterruptProcessingException() return self.load_image(urls[0]['filename']+" [temp]") diff --git a/js/popup.js b/js/popup.js index daab872..3c07300 100644 --- a/js/popup.js +++ b/js/popup.js @@ -15,6 +15,7 @@ class Log { static error(e) { console.error(e) } static message_in(message, extra) { if (message.detail && !message.detail.tick) Log.log(`--> ${JSON.stringify(message.detail)}` + (extra ? ` ${extra}` : "")) + if (message.detail && message.detail.tick) Log.log(`--> tick`) } static message_out(response, extra) { Log.log(`"<-- ${JSON.stringify(response)}` + (extra ? ` ${extra}` : "")) @@ -96,7 +97,10 @@ class Popup extends HTMLSpanElement { } _send_response(msg, special_message, keep_open) { - if (Date.now()-this.last_response_sent < 1000) Log.message_out(msg, "(throttled)") + if (Date.now()-this.last_response_sent < 1000) { + Log.message_out(msg, "(throttled)") + return + } if (!special_message) { Array.from(this.extras.children).forEach((e)=>{ msg = msg + "|||" + e.value })