Skip to content

Instantly share code, notes, and snippets.

@mittenchops
Last active December 19, 2015 18:39
Show Gist options
  • Save mittenchops/6000829 to your computer and use it in GitHub Desktop.
Save mittenchops/6000829 to your computer and use it in GitHub Desktop.
How to use multiprocessing
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