If only one worker, run in main thread to avoid overhead

This commit is contained in:
Luigi311
2024-01-06 01:13:15 -07:00
parent 7317e8533d
commit 95f2a9ad30

View File

@@ -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