Skip to content

Instantly share code, notes, and snippets.

@smutch
Created August 15, 2012 08:58
Show Gist options
  • Save smutch/3357805 to your computer and use it in GitHub Desktop.
Save smutch/3357805 to your computer and use it in GitHub Desktop.
Lite command line wrapper around littleworkers.
#!/usr/bin/env python
"""Lite command line wrapper around littleworkers."""
from littleworkers import Pool
import multiprocessing
from optparse import OptionParser
if __name__ == '__main__':
AVAILCORES = multiprocessing.cpu_count()
parser = OptionParser()
parser.add_option(
'-w',
'--workers',
type=int,
dest='workers',
default=2,
help='number of workers in pool (-1 -> ncores)',
metavar='NUM',
)
(opt, commands) = parser.parse_args()
if opt.workers==-1:
opt.workers = AVAILCORES
elif opt.workers>AVAILCORES:
raise ValueError("Number of workers requested exceeds "\
"number of available cores.")
# Setup a pool.
lil = Pool(workers=opt.workers)
# Run!
lil.run(commands)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment