ComfyUI
ComfyUI copied to clipboard
Fix RecursionError for (very) large graphs
ExecutionList adds nodes and links recursively. There are 3 recursive calls per node in a chain of nodes, which means you run into recursion limits at around 300 linked nodes (default recursion limit is 1000 in CPython).
File "C:\Dev\ComfyUI\execution.py", line 492, in execute
execution_list.add_node(node_id)
File "C:\Dev\ComfyUI\comfy_execution\graph.py", line 125, in add_node
self.add_strong_link(from_node_id, from_socket, unique_id)
File "C:\Dev\ComfyUI\comfy_execution\graph.py", line 153, in add_strong_link
super().add_strong_link(from_node_id, from_socket, to_node_id)
File "C:\Dev\ComfyUI\comfy_execution\graph.py", line 102, in add_strong_link
self.add_node(from_node_id)
File "C:\Dev\ComfyUI\comfy_execution\graph.py", line 125, in add_node
self.add_strong_link(from_node_id, from_socket, unique_id)
File "C:\Dev\ComfyUI\comfy_execution\graph.py", line 153, in add_strong_link
super().add_strong_link(from_node_id, from_socket, to_node_id)
File "C:\Dev\ComfyUI\comfy_execution\graph.py", line 102, in add_strong_link
self.add_node(from_node_id)
[ ... repeats many times ...]
RecursionError: maximum recursion depth exceeded
This PR makes TopologicalSort.add_node add inputs in a while loop to avoid the problem.
(Automated Bot Message) CI Tests are running, you can view the results at https://ci.comfy.org/?branch=4886%2Fmerge