Skip to content

Instantly share code, notes, and snippets.

@daerduoCarey
Created August 20, 2017 22:49
Show Gist options
  • Save daerduoCarey/7efff3fe76092015eb9f15bb9322591a to your computer and use it in GitHub Desktop.
Save daerduoCarey/7efff3fe76092015eb9f15bb9322591a to your computer and use it in GitHub Desktop.
run_parallel.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-
'''
MOVED FROM /orions4-zfs/projects/rqi/Code/3dcnn/lfd/run_parallel.py
PLEASE CHECK ORIGINAL FILE FOR UPDATES!
'''
import os
import sys
import datetime
from functools import partial
from multiprocessing.dummy import Pool
from subprocess import call
'''
@brief:
run commands in parallel
@usage:
python run_parallel.py command_list.txt
where each line of command_list.txt is a executable command
'''
command_file = sys.argv[1]
commands = [line.rstrip() for line in open(command_file)]
report_step = 10
pool = Pool(10)
for idx, return_code in enumerate(pool.imap(partial(call, shell=True), commands)):
if idx % report_step == 0:
print('[%s] command %d of %d' % (datetime.datetime.now().time(), idx, len(commands)))
if return_code != 0:
print('!! command %d of %d (\"%s\") failed' % (idx, len(commands), commands[idx]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment