From 163bfff829a962d2bfddd1a88743060cc65b2e91 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Thu, 19 Sep 2024 17:24:51 +0900 Subject: [PATCH] `.shutdown` isn't so friendly :( --- folder_paths.py | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/folder_paths.py b/folder_paths.py index 4ba9856dfc4..5386dcbfb86 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -1,7 +1,6 @@ from __future__ import annotations -import asyncio, threading -from functools import partial, wraps +import threading import os import time import mimetypes @@ -199,23 +198,31 @@ def recursive_search(directory: str, excluded_dir_names: list[str] | None=None) logging.debug("recursive file list on directory {}".format(directory)) with ThreadPoolExecutor() as executor: + calls = [] def proc_subdir(path: str): dirs[path] = os.path.getmtime(path) def handle(file): - if not os.path.isdir(file): - relative_path = os.path.relpath(file, directory) - result.append(relative_path) - return - executor.submit(lambda: proc_subdir(file)) - for subdir in os.listdir(file): - path = os.path.join(file, subdir) - if subdir not in excluded_dir_names: - executor.submit(lambda: handle(path)) - - executor.submit(lambda: handle(directory)) - executor.shutdown(wait=True) + try: + if not os.path.isdir(file): + relative_path = os.path.relpath(file, directory) + result.append(relative_path) + return + + calls.append(executor.submit(lambda: proc_subdir(file))) + + for subdir in os.listdir(file): + path = os.path.join(file, subdir) + if subdir not in excluded_dir_names: + calls.append(executor.submit(lambda: handle(path))) + except Exception as e: + logging.error(f"Error while handling {file}: {e}") + + calls.append(executor.submit(lambda: handle(directory))) + while len(calls) > 0: + calls.pop().result() + logging.debug("found {} files".format(len(result))) return result, dirs