Created
August 15, 2012 08:58
-
-
Save smutch/3357805 to your computer and use it in GitHub Desktop.
Lite command line wrapper around littleworkers.
This file contains hidden or 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 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