Last active
August 29, 2015 13:57
-
-
Save mittenchops/9783528 to your computer and use it in GitHub Desktop.
Multiprocessing for a small set of things all simultaneous
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
# 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