Created
March 11, 2021 13:22
-
-
Save surt91/be44396ff9f6a09d17a139bfd64dc497 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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