Skip to content

Commit

Permalink
Limit black workers to minimum of 60 or cpu count
Browse files Browse the repository at this point in the history
We can have more than 1, just not more than 60
  • Loading branch information
ThadHouse committed Jan 11, 2024
1 parent 3da80e2 commit e94db5b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion wpiformat/wpiformat/pyformat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This task runs black on files with Python extension."""

import multiprocessing as mp
import subprocess
import sys

Expand All @@ -14,10 +15,11 @@ def should_process_file(config_file, name):
@staticmethod
def run_batch(config_file, names):
try:
cpu_count = min(60, mp.cpu_count())
# Force one worker because wpiformat already uses a process pool,
# and we need to keep the total number of multiprocessing processes
# below the Windows system limit.
args = [sys.executable, "-m", "black", "--workers", "1", "-q"]
args = [sys.executable, "-m", "black", "--workers", str(cpu_count), "-q"]
subprocess.run(args + names)
except FileNotFoundError:
print("Error: black not found in PATH. Is it installed?", file=sys.stderr)
Expand Down

0 comments on commit e94db5b

Please sign in to comment.