db_run.py 636 B

12345678910111213141516171819
  1. import subprocess
  2. from concurrent.futures import ThreadPoolExecutor
  3. from pathlib import Path
  4. def task(name: str) -> subprocess.Popen:
  5. logfile = Path(name).parent.parent / "logs" / (Path(name).name + ".log")
  6. return subprocess.Popen(f'C:\\Windows\\System32\\cmd.exe /C "{name} 1"', stdout=logfile.open("w")).wait()
  7. def run(base_dir: str, max: int = 5) -> None:
  8. files = [str(f) for f in Path(base_dir).glob("*.bat") if not f.name.startswith("_")]
  9. with ThreadPoolExecutor(max_workers=max) as executor:
  10. executor.map(task, files)
  11. if __name__ == "__main__":
  12. run("C:\\GlobalCube\\System\\OPTIMA\\SQL\\batch")