db_run.py 812 B

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