From 873735900f0bd55acae71d83f4cc2e5d47c24acb Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Wed, 10 Jan 2024 02:12:57 -0700 Subject: [PATCH] Functions: Add override_threads Signed-off-by: Luigi311 --- src/functions.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/functions.py b/src/functions.py index 2d3d306..3da2b2f 100644 --- a/src/functions.py +++ b/src/functions.py @@ -93,11 +93,18 @@ def search_mapping(dictionary: dict, key_value: str): return None -def future_thread_executor(args: list, threads: int = 32): +def future_thread_executor( + args: list, threads: int = None, override_threads: bool = False +): futures_list = [] results = [] - workers = min(int(os.getenv("MAX_THREADS", 32)), os.cpu_count() * 2, threads) + workers = min(int(os.getenv("MAX_THREADS", 32)), os.cpu_count() * 2) + if threads: + workers = min(threads, workers) + + if override_threads: + workers = threads # If only one worker, run in main thread to avoid overhead if workers == 1: