Skip to content

Instantly share code, notes, and snippets.

@mikluko
Created March 11, 2011 07:59
Show Gist options
  • Save mikluko/865596 to your computer and use it in GitHub Desktop.
Save mikluko/865596 to your computer and use it in GitHub Desktop.
workaround for Issue5228 (see http://bugs.python.org/issue5228)
from functools import partial
from multiprocessing import Pool
import sys
def power(x, pwr=2):
return x**pwr
def uncurry(r):
return power(r[0], **r[1])
def curry(cases, **kwargs):
for case in cases:
yield case, kwargs
if __name__ == "__main__":
pool = Pool()
cases = [3,4,5]
if sys.version_info < (2, 7):
print 'version %d.%d.%d (< 2.7)' % sys.version_info[:3]
results = pool.map(uncurry, curry(cases, pwr=3))
else:
print 'version %d.%d.%d (>= 2.7)' % sys.version_info[:3]
results = pool.map(partial(power, pwr=3), cases)
print results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment