-
-
Save absognety/d1a8f8a0f663686e0a91aa744b64faca to your computer and use it in GitHub Desktop.
Template for Python multiprocessing and multithreading
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
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