Skip to content

Commit

Permalink
call run_extensions_installer() using executor
Browse files Browse the repository at this point in the history
  • Loading branch information
wkpark committed Oct 12, 2024
1 parent 4823909 commit ca34755
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions modules/launch_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import shlex
from functools import lru_cache

from concurrent.futures import ThreadPoolExecutor, as_completed
from modules import cmd_args, errors
from modules.paths_internal import script_path, extensions_dir
from modules.timer import startup_timer
Expand Down Expand Up @@ -228,7 +229,10 @@ def version_check(commit):
def run_extension_installer(extension_dir):
path_installer = os.path.join(extension_dir, "install.py")
if not os.path.isfile(path_installer):
return
return False

dirname = os.path.basename(extension_dir)
logging.debug(f"Installing {dirname}")

try:
env = os.environ.copy()
Expand All @@ -240,6 +244,8 @@ def run_extension_installer(extension_dir):
except Exception as e:
errors.report(str(e))

return True


def list_extensions(settings_file):
settings = {}
Expand Down Expand Up @@ -267,14 +273,19 @@ def run_extensions_installers(settings_file):
return

with startup_timer.subcategory("run extensions installers"):
paths = {}
for dirname_extension in list_extensions(settings_file):
logging.debug(f"Installing {dirname_extension}")

path = os.path.join(extensions_dir, dirname_extension)

if os.path.isdir(path):
run_extension_installer(path)
startup_timer.record(dirname_extension)
paths[dirname_extension] = path

with ThreadPoolExecutor(max_workers=2) as executor:
futures = {executor.submit(run_extension_installer, path): dirname_extension for dirname_extension, path in paths.items()}
for future in as_completed(futures):
dirname_extension = futures[future]
if future.result():
startup_timer.record(dirname_extension)


re_requirement = re.compile(r"\s*([-_a-zA-Z0-9]+)\s*(?:==\s*([-+_.a-zA-Z0-9]+))?\s*")
Expand Down

0 comments on commit ca34755

Please sign in to comment.