Last active
December 19, 2015 18:39
-
-
Save mittenchops/6000829 to your computer and use it in GitHub Desktop.
How to use multiprocessing
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
from multiprocessing import Pool | |
from functools import partial | |
x = [1,2,3] | |
y = 10 | |
# NOTE, f CANNOT be a lambda function: http://stackoverflow.com/questions/17657571/python-multiprocessing-map-function-error | |
def f(x,y): | |
return(x**2+y) | |
# ordinary map works: | |
map(partial(f,y=y),x) | |
# [11, 14, 19] | |
# multiprocessing does, too. | |
p = Pool(4) | |
p.map(partial(f, y=y), x) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment