import subprocess from concurrent.futures import ThreadPoolExecutor from functools import partial from pathlib import Path from database.model import DbCreateConfig def task(name: str, increment: bool = True) -> subprocess.Popen: logfile = Path(name).parent.parent / "logs" / (Path(name).name + ".log") flag = "1" if increment else "" return subprocess.Popen(f'C:\\Windows\\System32\\cmd.exe /C "{name} {flag}"', stdout=logfile.open("w")).wait() def run(config_file: str, increment: bool, max: int) -> None: cfg = DbCreateConfig.load_config(config_file) files = [str(f) for f in Path(cfg.batch_dir).glob("*.bat") if not f.name.startswith("_")] task2 = partial(task, increment=increment) with ThreadPoolExecutor(max_workers=max) as executor: executor.map(task2, files)