Skip to content

Instantly share code, notes, and snippets.

@boukeversteegh
Last active December 15, 2015 10:29
Show Gist options
  • Save boukeversteegh/5246009 to your computer and use it in GitHub Desktop.
Save boukeversteegh/5246009 to your computer and use it in GitHub Desktop.
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