Created
September 10, 2014 03:14
-
-
Save lxneng/555aadfa60e2656df320 to your computer and use it in GitHub Desktop.
Simple Python Parallelism
This file contains hidden or 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 | |
def parallel_function(f): | |
def parallize(f, seq): | |
pool = Pool() | |
pool.map(f, seq) | |
pool.close() | |
pool.join() | |
return partial(parallize, f) | |
def test(n): | |
print(n+1) | |
test.parallel = parallel_function(test) | |
test.parallel(range(1000000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment