Last active
December 15, 2015 10:29
-
-
Save boukeversteegh/5246009 to your computer and use it in GitHub Desktop.
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 | |
# Define a function | |
square = lambda x: x**2 | |
if __name__ == "__main__": | |
mylist = [1, 2, 3, 4, 9, 2, 5, 2, 7, 0, 5, 4, 1, 3, 5, 7] | |
# Create a pool with 8 multicore threads | |
# Apply the function to all arguments in the list | |
pool = multiprocessing.Pool(8) | |
result = pool.map(square, mylist) | |
print result | |
# [1, 4, 9, 16, 81, 4, 25, 4, 49, 0, 25, 16, 9, 25, 49] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment