Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
0faee118
Unverified
Commit
0faee118
authored
Aug 28, 2023
by
Dr.Lt.Data
Committed by
GitHub
Aug 28, 2023
Browse files
support on prompt event handler (#765)
Co-authored-by:
Lt.Dr.Data
<
lt.dr.data@gmail.com
>
parent
b8c7c770
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
0 deletions
+17
-0
server.py
server.py
+17
-0
No files found.
server.py
View file @
0faee118
import
os
import
os
import
sys
import
sys
import
asyncio
import
asyncio
import
traceback
import
nodes
import
nodes
import
folder_paths
import
folder_paths
import
execution
import
execution
...
@@ -88,6 +90,8 @@ class PromptServer():
...
@@ -88,6 +90,8 @@ class PromptServer():
self
.
last_node_id
=
None
self
.
last_node_id
=
None
self
.
client_id
=
None
self
.
client_id
=
None
self
.
on_prompt_handlers
=
[]
@
routes
.
get
(
'/ws'
)
@
routes
.
get
(
'/ws'
)
async
def
websocket_handler
(
request
):
async
def
websocket_handler
(
request
):
ws
=
web
.
WebSocketResponse
()
ws
=
web
.
WebSocketResponse
()
...
@@ -438,6 +442,7 @@ class PromptServer():
...
@@ -438,6 +442,7 @@ class PromptServer():
resp_code
=
200
resp_code
=
200
out_string
=
""
out_string
=
""
json_data
=
await
request
.
json
()
json_data
=
await
request
.
json
()
json_data
=
self
.
trigger_on_prompt
(
json_data
)
if
"number"
in
json_data
:
if
"number"
in
json_data
:
number
=
float
(
json_data
[
'number'
])
number
=
float
(
json_data
[
'number'
])
...
@@ -606,3 +611,15 @@ class PromptServer():
...
@@ -606,3 +611,15 @@ class PromptServer():
if
call_on_start
is
not
None
:
if
call_on_start
is
not
None
:
call_on_start
(
address
,
port
)
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment