Skip to content

Instantly share code, notes, and snippets.

@surt91
Created March 11, 2021 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save surt91/be44396ff9f6a09d17a139bfd64dc497 to your computer and use it in GitHub Desktop.
Save surt91/be44396ff9f6a09d17a139bfd64dc497 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import sys
if len(sys.argv) != 2:
print("expect exactly one argument: filename to commands")
sys.exit(1)
filename = sys.argv[1]
if not os.path.exists(filename):
print("command file does not exists:", filename)
sys.exit(1)
from multiprocessing import Pool, current_process
p = Pool()
with open(filename) as f:
cmds = [line.strip() for line in f]
def execute(cmd):
id = current_process().ident
print(id, cmd)
os.system(cmd)
with Pool() as p:
p.map(execute, cmds, chunksize=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment