Skip to content

Instantly share code, notes, and snippets.

@lxneng
Created September 10, 2014 03:14
Show Gist options
  • Save lxneng/555aadfa60e2656df320 to your computer and use it in GitHub Desktop.
Save lxneng/555aadfa60e2656df320 to your computer and use it in GitHub Desktop.
Simple Python Parallelism
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