Last active
August 28, 2015 18:53
-
-
Save bhatman/28014b4b6a1c4ea0a83b to your computer and use it in GitHub Desktop.
basically the TLDR of http://chriskiehl.com/article/parallelism-in-one-line/
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/python | |
from multiprocessing.dummy import Pool as ThreadPool | |
# arbitrary. could base this on the number of cores | |
PARALLELISM = 5 | |
pool = ThreadPool(PARALLELISM) | |
def function_to_apply(item): | |
# do things with item | |
raise NotImplementedError() | |
things_to_process = list() | |
results = pool.map(function_to_apply, things_to_process) | |
pool.close() | |
pool.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment