diff --git a/wpiformat/wpiformat/pyformat.py b/wpiformat/wpiformat/pyformat.py index 4c2a6c2..f9b5bac 100644 --- a/wpiformat/wpiformat/pyformat.py +++ b/wpiformat/wpiformat/pyformat.py @@ -1,5 +1,6 @@ """This task runs black on files with Python extension.""" +import multiprocessing as mp import subprocess import sys @@ -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)