From 6318dcba7a111e2faf4a931da5fd341c2f96e6cd Mon Sep 17 00:00:00 2001 From: Thad House Date: Wed, 10 Jan 2024 23:17:26 -0800 Subject: [PATCH] Limit black workers to minimum of 60 or cpu count (#271) We can have more than 1, just not more than 60 --- wpiformat/wpiformat/pyformat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wpiformat/wpiformat/pyformat.py b/wpiformat/wpiformat/pyformat.py index 4c2a6c2..ba4b2ee 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: - # 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)