From 95f2a9ad308684d456f4b5451faed7e40fdfcea9 Mon Sep 17 00:00:00 2001 From: Luigi311 Date: Sat, 6 Jan 2024 01:13:15 -0700 Subject: [PATCH] If only one worker, run in main thread to avoid overhead --- src/functions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/functions.py b/src/functions.py index c1c160b..2d3d306 100644 --- a/src/functions.py +++ b/src/functions.py @@ -99,6 +99,13 @@ def future_thread_executor(args: list, threads: int = 32): workers = min(int(os.getenv("MAX_THREADS", 32)), os.cpu_count() * 2, threads) + # If only one worker, run in main thread to avoid overhead + if workers == 1: + results = [] + for arg in args: + results.append(arg[0](*arg[1:])) + return results + with ThreadPoolExecutor(max_workers=workers) as executor: for arg in args: # * arg unpacks the list into actual arguments