From df74c3c6385ddec225aaa630c77c95b9da0363b2 Mon Sep 17 00:00:00 2001 From: Haoming Date: Tue, 29 Oct 2024 14:12:42 +0800 Subject: [PATCH 1/2] threading --- modules/ui_extensions.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/ui_extensions.py b/modules/ui_extensions.py index 23aff709627..3f62e05180c 100644 --- a/modules/ui_extensions.py +++ b/modules/ui_extensions.py @@ -106,7 +106,7 @@ def check_updates(id_task, disable_list): exts = [ext for ext in extensions.extensions if ext.remote is not None and ext.name not in disabled] shared.state.job_count = len(exts) - for ext in exts: + def _check_update(ext): shared.state.textinfo = ext.name try: @@ -117,6 +117,14 @@ def check_updates(id_task, disable_list): except Exception: errors.report(f"Error checking updates for {ext.name}", exc_info=True) + threads = [] + for ext in exts: + thread = threading.Thread(target=_check_update, args=(ext,)) + thread.start() + threads.append(thread) + + for thread in threads: + thread.join() shared.state.nextjob() return extension_table(), "" From 95686227bd2f3710ad62299c69966730a27debfa Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Tue, 29 Oct 2024 20:16:15 +0900 Subject: [PATCH 2/2] limit number of simultaneous updates shared.opts.concurrent_git_fetch_limit --- modules/shared_options.py | 1 + modules/ui_extensions.py | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/modules/shared_options.py b/modules/shared_options.py index efede7067f2..0bb508753b7 100644 --- a/modules/shared_options.py +++ b/modules/shared_options.py @@ -128,6 +128,7 @@ "disable_mmap_load_safetensors": OptionInfo(False, "Disable memmapping for loading .safetensors files.").info("fixes very slow loading speed in some cases"), "hide_ldm_prints": OptionInfo(True, "Prevent Stability-AI's ldm/sgm modules from printing noise to console."), "dump_stacks_on_signal": OptionInfo(False, "Print stack traces before exiting the program with ctrl+c."), + "concurrent_git_fetch_limit": OptionInfo(16, "Number of simultaneous extension update checks ", gr.Slider, {"step": 1, "minimum": 1, "maximum": 100}).info("reduce extension update check time"), })) options_templates.update(options_section(('profiler', "Profiler", "system"), { diff --git a/modules/ui_extensions.py b/modules/ui_extensions.py index 3f62e05180c..b973c08d037 100644 --- a/modules/ui_extensions.py +++ b/modules/ui_extensions.py @@ -1,5 +1,6 @@ import json import os +from concurrent.futures import ThreadPoolExecutor import threading import time from datetime import datetime, timezone @@ -106,26 +107,24 @@ def check_updates(id_task, disable_list): exts = [ext for ext in extensions.extensions if ext.remote is not None and ext.name not in disabled] shared.state.job_count = len(exts) - def _check_update(ext): - shared.state.textinfo = ext.name + lock = threading.Lock() + def _check_update(ext): try: ext.check_updates() except FileNotFoundError as e: if 'FETCH_HEAD' not in str(e): raise except Exception: - errors.report(f"Error checking updates for {ext.name}", exc_info=True) - - threads = [] - for ext in exts: - thread = threading.Thread(target=_check_update, args=(ext,)) - thread.start() - threads.append(thread) - - for thread in threads: - thread.join() - shared.state.nextjob() + with lock: + errors.report(f"Error checking updates for {ext.name}", exc_info=True) + with lock: + shared.state.textinfo = ext.name + shared.state.nextjob() + + with ThreadPoolExecutor(max_workers=max(1, int(shared.opts.concurrent_git_fetch_limit))) as executor: + for ext in exts: + executor.submit(_check_update, ext) return extension_table(), ""