diff --git a/main.py b/main.py index 2da78d7a..802e4bfe 100644 --- a/main.py +++ b/main.py @@ -1,22 +1,24 @@ import os import importlib.util import folder_paths - +import time def execute_prestartup_script(): def execute_script(script_path): - if os.path.exists(script_path): - module_name = os.path.splitext(script_path)[0] - try: - spec = importlib.util.spec_from_file_location(module_name, script_path) - module = importlib.util.module_from_spec(spec) - spec.loader.exec_module(module) - except Exception as e: - print(f"Failed to execute startup-script: {script_path} / {e}") + module_name = os.path.splitext(script_path)[0] + try: + spec = importlib.util.spec_from_file_location(module_name, script_path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return True + except Exception as e: + print(f"Failed to execute startup-script: {script_path} / {e}") + return False node_paths = folder_paths.get_folder_paths("custom_nodes") for custom_node_path in node_paths: possible_modules = os.listdir(custom_node_path) + node_prestartup_times = [] for possible_module in possible_modules: module_path = os.path.join(custom_node_path, possible_module) @@ -24,8 +26,19 @@ def execute_prestartup_script(): continue script_path = os.path.join(module_path, "prestartup_script.py") - execute_script(script_path) - + if os.path.exists(script_path): + time_before = time.perf_counter() + success = execute_script(script_path) + node_prestartup_times.append((time.perf_counter() - time_before, module_path, success)) + if len(node_prestartup_times) > 0: + print("\nPrestartup times for custom nodes:") + for n in sorted(node_prestartup_times): + if n[2]: + import_message = "" + else: + import_message = " (PRESTARTUP FAILED)" + print("{:6.1f} seconds{}:".format(n[0], import_message), n[1]) + print() execute_prestartup_script() @@ -36,7 +49,6 @@ import itertools import shutil import threading import gc -import time from comfy.cli_args import args import comfy.utils