Skip to content

Instantly share code, notes, and snippets.

@mittenchops
Last active August 29, 2015 13:57
Show Gist options
  • Save mittenchops/9783528 to your computer and use it in GitHub Desktop.
Save mittenchops/9783528 to your computer and use it in GitHub Desktop.
Multiprocessing for a small set of things all simultaneous
# via here: http://stackoverflow.com/questions/5442910/python-multiprocessing-pool-map-for-multiple-arguments
from multiprocessing import Process, Pipe
from itertools import izip
def spawn(f):
def fun(pipe,x):
pipe.send(f(x))
pipe.close()
return fun
def parmap(f,X):
pipe=[Pipe() for x in X]
proc=[Process(target=spawn(f),args=(c,x)) for x,(p,c) in izip(X,pipe)]
[p.start() for p in proc]
[p.join() for p in proc]
return [p.recv() for (p,c) in pipe]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment