mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-12 07:10:52 +08:00
support on prompt event handler
This commit is contained in:
parent
67833c83d8
commit
9d41a9d533
17
server.py
17
server.py
@ -1,6 +1,8 @@
|
||||
import os
|
||||
import sys
|
||||
import asyncio
|
||||
import traceback
|
||||
|
||||
import nodes
|
||||
import folder_paths
|
||||
import execution
|
||||
@ -79,6 +81,8 @@ class PromptServer():
|
||||
self.last_node_id = None
|
||||
self.client_id = None
|
||||
|
||||
self.on_prompt_handlers = []
|
||||
|
||||
@routes.get('/ws')
|
||||
async def websocket_handler(request):
|
||||
ws = web.WebSocketResponse()
|
||||
@ -386,6 +390,7 @@ class PromptServer():
|
||||
resp_code = 200
|
||||
out_string = ""
|
||||
json_data = await request.json()
|
||||
json_data = self.trigger_on_prompt(json_data)
|
||||
|
||||
if "number" in json_data:
|
||||
number = float(json_data['number'])
|
||||
@ -521,3 +526,15 @@ class PromptServer():
|
||||
if call_on_start is not None:
|
||||
call_on_start(address, port)
|
||||
|
||||
def add_on_prompt_handler(self, handler):
|
||||
self.on_prompt_handlers.append(handler)
|
||||
|
||||
def trigger_on_prompt(self, json_data):
|
||||
for handler in self.on_prompt_handlers:
|
||||
try:
|
||||
json_data = handler(json_data)
|
||||
except Exception as e:
|
||||
print(f"[ERROR] An error occurred during the on_prompt_handler processing")
|
||||
traceback.print_exc()
|
||||
|
||||
return json_data
|
||||
|
||||
Loading…
Reference in New Issue
Block a user