MCPcopy Create free account
hub / github.com/Comfy-Org/ComfyUI / execute_async

Method execute_async

execution.py:726–831  ·  view source on GitHub ↗
(self, prompt, prompt_id, extra_data={}, execute_outputs=[])

Source from the content-addressed store, hash-verified

724 asyncio.run(self.execute_async(prompt, prompt_id, extra_data, execute_outputs))
725
726 async def execute_async(self, prompt, prompt_id, extra_data={}, execute_outputs=[]):
727 set_preview_method(extra_data.get("preview_method"))
728
729 nodes.interrupt_processing(False)
730
731 if "client_id" in extra_data:
732 self.server.client_id = extra_data["client_id"]
733 else:
734 self.server.client_id = None
735
736 self.status_messages = []
737 self.add_message("execution_start", { "prompt_id": prompt_id}, broadcast=False)
738
739 self._notify_prompt_lifecycle("start", prompt_id)
740 ram_headroom = int(self.cache_args["ram"] * (1024 ** 3))
741 ram_inactive_headroom = int(self.cache_args["ram_inactive"] * (1024 ** 3))
742 ram_release_callback = self.caches.outputs.ram_release if self.cache_type == CacheType.RAM_PRESSURE else None
743 comfy.memory_management.set_ram_cache_release_state(ram_release_callback, ram_headroom)
744
745 try:
746 with torch.inference_mode():
747 dynamic_prompt = DynamicPrompt(prompt)
748 reset_progress_state(prompt_id, dynamic_prompt)
749 add_progress_handler(WebUIProgressHandler(self.server))
750 is_changed_cache = IsChangedCache(prompt_id, dynamic_prompt, self.caches.outputs)
751 for cache in self.caches.all:
752 await cache.set_prompt(dynamic_prompt, prompt.keys(), is_changed_cache)
753 cache.clean_unused()
754
755 node_ids = list(prompt.keys())
756 cache_results = await asyncio.gather(
757 *(self.caches.outputs.get(node_id) for node_id in node_ids)
758 )
759 cached_nodes = [
760 node_id for node_id, result in zip(node_ids, cache_results)
761 if result is not None
762 ]
763
764 comfy.model_management.cleanup_models_gc()
765 self.add_message("execution_cached",
766 { "nodes": cached_nodes, "prompt_id": prompt_id},
767 broadcast=False)
768 pending_subgraph_results = {}
769 pending_async_nodes = {} # TODO - Unify this with pending_subgraph_results
770 ui_node_outputs = {}
771 executed = set()
772 execution_list = ExecutionList(dynamic_prompt, self.caches.outputs)
773 current_outputs = self.caches.outputs.all_node_ids()
774 for node_id in list(execute_outputs):
775 execution_list.add_node(node_id)
776
777 while not execution_list.is_empty():
778 node_id, error, ex = await execution_list.stage_node_execution()
779 if error is not None:
780 self.handle_execution_error(prompt_id, dynamic_prompt.original_prompt, current_outputs, executed, error, ex)
781 break
782
783 assert node_id is not None, "Node ID should not be None at this point"

Callers 1

executeMethod · 0.95

Calls 15

add_messageMethod · 0.95
stage_node_executionMethod · 0.95
all_node_idsMethod · 0.95
get_display_node_idMethod · 0.95
set_preview_methodFunction · 0.90
DynamicPromptClass · 0.90
reset_progress_stateFunction · 0.90
add_progress_handlerFunction · 0.90

Tested by

no test coverage detected