-
-
Save petzel/e40c63088ba1a5609708736dd6f39ea4 to your computer and use it in GitHub Desktop.
Template for Python multiprocessing and multithreading
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
import multiprocessing #:) | |
def do_this(number): | |
print number | |
return number*2 | |
# Create a list to iterate over. | |
# (Note: Multiprocessing only accepts one item at a time) | |
some_list = range(0,10) | |
# Multiprocessing :) | |
num_proc = multiprocessing.cpu_count() # use all processors | |
num_proc = 6 # specify number to use (to be nice) | |
p = multiprocessing.Pool(num_proc) | |
result = p.map(do_this, some_list) | |
p.close() | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment