Created
July 2, 2013 02:32
-
-
Save anonymous/5906387 to your computer and use it in GitHub Desktop.
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
def add_concurrent_options(parser, prefer_threads=False): | |
# Adds relevant options to parser | |
parser.add_argument("--workers", choices=("threads", "processes"), default="threads" if prefer_threads else "processes", | |
help="Select if concurrency is done using threads or processes [%(default)s]") | |
parser.add_argument("--single", action="store_true", help="Uses a single thread for concurrency. This makes debugging a lot easier") | |
import multiprocessing | |
def get_concurrent_executor(options): | |
# Gets a suitable executor | |
if options.workers=="threads" or options.single: | |
workers=multiprocessing.cpu_count() if not options.single else 1 | |
return futures.ThreadPoolExecutor(max_workers=workers) | |
return futures.ProcessPoolExecutor() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment