Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API polling to check the execution progress status of the current task #5551

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@ class ExecutionResult(Enum):
FAILURE = 1
PENDING = 2

# Add global variables to track the number of nodes
total_nodes = 0
executed_nodes = 0

# Add a function to clear statistical information
def reset_node_counts():
global total_nodes, executed_nodes
total_nodes = 0
executed_nodes = 0

# Add a function to count the total number of nodes
def count_total_nodes(task_graph):
global total_nodes
total_nodes = len(task_graph)
#end

class DuplicateNodeError(Exception):
pass

Expand All @@ -39,6 +55,9 @@ def get(self, node_id):
node = self.dynprompt.get_node(node_id)
class_type = node["class_type"]
class_def = nodes.NODE_CLASS_MAPPINGS[class_type]
#Initialization statistics <start>
reset_node_counts()
#Initialization statistics <end>
if not hasattr(class_def, "IS_CHANGED"):
self.is_changed[node_id] = False
return self.is_changed[node_id]
Expand Down Expand Up @@ -249,6 +268,10 @@ def execute(server, dynprompt, caches, current_item, extra_data, executed, promp
inputs = dynprompt.get_node(unique_id)['inputs']
class_type = dynprompt.get_node(unique_id)['class_type']
class_def = nodes.NODE_CLASS_MAPPINGS[class_type]
#execute node count <start>
global executed_nodes
executed_nodes+=1
#execute node count <end>
if caches.outputs.get(unique_id) is not None:
if server.client_id is not None:
cached_output = caches.ui.get(unique_id) or {}
Expand Down Expand Up @@ -479,6 +502,11 @@ def execute(self, prompt, prompt_id, extra_data={}, execute_outputs=[]):
for node_id in prompt:
if self.caches.outputs.get(node_id) is not None:
cached_nodes.append(node_id)
#Count the number of task nodes <start>
else:
global total_nodes
total_nodes+=1
#Count the number of task nodes <end>

comfy.model_management.cleanup_models(keep_clone_weights_loaded=True)
self.add_message("execution_cached",
Expand Down
10 changes: 10 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,16 @@ def __init__(self, loop):

self.on_prompt_handlers = []

#add api get progress status <start>
async def get_node_status(request):
return web.json_response({
"total_nodes": execution.total_nodes,
"executed_nodes": execution.executed_nodes
})
routes.get('/node_status')(get_node_status)
self.app.add_routes(routes)
#add api get progress status <end>

@routes.get('/ws')
async def websocket_handler(request):
ws = web.WebSocketResponse()
Expand Down