db_run.py 560 B

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