prebuild should have its own executor

otherwise it can lock itself due to the very awkward hack of python threading instead of genuine async handling
This commit is contained in:
Alex "mcmonkey" Goodwin 2024-10-03 13:27:04 -07:00
parent 409f4b6583
commit 6fca6e1746

View File

@ -5,7 +5,6 @@ import os
import time import time
import mimetypes import mimetypes
import logging import logging
import time
from typing import Set, List, Dict, Tuple, Literal from typing import Set, List, Dict, Tuple, Literal
from collections.abc import Collection from collections.abc import Collection
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
@ -217,13 +216,14 @@ def get_folder_paths(folder_name: str) -> list[str]:
def prebuild_lists(): def prebuild_lists():
start_time = time.time() start_time = time.perf_counter()
calls = [] with ThreadPoolExecutor(32) as executor:
for folder_name in folder_names_and_paths: calls = []
calls.append(async_executor.submit(lambda: get_filename_list(folder_name))) for folder_name in folder_names_and_paths:
for call in calls: calls.append(executor.submit(lambda: get_filename_list(folder_name)))
call.result() for call in calls:
end_time = time.time() call.result()
end_time = time.perf_counter()
logging.info("Scanned model lists in {:.2f} seconds".format(end_time - start_time)) logging.info("Scanned model lists in {:.2f} seconds".format(end_time - start_time))