From 0d2b1eb95bc1cf1316af13184c313e35db19cb9b Mon Sep 17 00:00:00 2001 From: telamonian Date: Sat, 1 Jun 2024 02:37:45 -0400 Subject: [PATCH] added EXTENSION_MODULES_LOADED guard set to prevent double loading of extensions --- .gitignore | 6 +++++- nodes.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9f0389241..fdddc4f23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ __pycache__/ *.py[cod] +*.egg-info/ /output/ /input/ !/input/example.png @@ -15,4 +16,7 @@ venv/ !/web/extensions/logging.js.example !/web/extensions/core/ /tests-ui/data/object_info.json -/user/ \ No newline at end of file +/user/ +.history/ +.vscode/ +*.code-workspace diff --git a/nodes.py b/nodes.py index 31e30b687..9522c7097 100644 --- a/nodes.py +++ b/nodes.py @@ -1861,11 +1861,20 @@ NODE_DISPLAY_NAME_MAPPINGS = { EXTENSION_WEB_DIRS = {} +EXTENSION_MODULES_LOADED = set() + def load_custom_node(module_path, ignore=set()): module_name = os.path.basename(module_path) if os.path.isfile(module_path): sp = os.path.splitext(module_path) module_name = sp[0] + + if module_name in EXTENSION_MODULES_LOADED: + logging.warning(f"Skip {module_path} module for custom nodes due to it already being loaded.") + return False + else: + EXTENSION_MODULES_LOADED.add(module_name) + try: logging.debug("Trying to load custom node {}".format(module_path)) if os.path.isfile(module_path): @@ -1928,16 +1937,30 @@ def load_custom_nodes(): def load_custom_nodes_entry_points(): base_node_names = set(NODE_CLASS_MAPPINGS.keys()) + extension_modules = set() for ep in entry_points(group="comfyui.node_class_mappings"): + if ep.module in EXTENSION_MODULES_LOADED: + logging.warning(f"Skip {ep.module} module for node_class_mappings entry point due to it already being loaded.") + continue + class_mapping = ep.load() for name in class_mapping: if name not in base_node_names: NODE_CLASS_MAPPINGS[name] = class_mapping[name] + extension_modules.add(ep.module) for ep in entry_points(group="comfyui.node_display_name_mappings"): + if ep.module in EXTENSION_MODULES_LOADED: + logging.warning(f"Skip {ep.module} module for node_display_name_mappings entry point due to it already being loaded.") + continue + display_name_mapping = ep.load() NODE_DISPLAY_NAME_MAPPINGS.update(display_name_mapping) + extension_modules.add(ep.module) + + # delay adding new module names to the guard set until after all possible entry_points are loaded + EXTENSION_MODULES_LOADED |= extension_modules def init_custom_nodes(): extras_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "comfy_extras")