Skip to content

Commit

Permalink
Limit black workers to minimum of 60 or cpu count (#271)
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 authored Jan 11, 2024
1 parent ea72b05 commit 6318dcb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions 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:
# Force one worker because wpiformat already uses a process pool,
# Force at max 60 workers because black uses multiprocessing,
# and we need to keep the total number of multiprocessing processes
# below the Windows system limit.
args = [sys.executable, "-m", "black", "--workers", "1", "-q"]
cpu_count = min(60, mp.cpu_count())
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 6318dcb

Please sign in to comment.