Skip to content

Commit 6318dcb

Browse files
authored
Limit black workers to minimum of 60 or cpu count (#271)
We can have more than 1, just not more than 60
1 parent ea72b05 commit 6318dcb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

wpiformat/wpiformat/pyformat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""This task runs black on files with Python extension."""
22

3+
import multiprocessing as mp
34
import subprocess
45
import sys
56

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

0 commit comments

Comments
 (0)