Skip to content

Commit

Permalink
If only one worker, run in main thread to avoid overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi311 committed Jan 6, 2024
1 parent 7317e85 commit 95f2a9a
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95f2a9a

Please sign in to comment.