Skip to content

Instantly share code, notes, and snippets.

@jarobins
Created September 11, 2013 17:00
Show Gist options
  • Save jarobins/6526580 to your computer and use it in GitHub Desktop.
Save jarobins/6526580 to your computer and use it in GitHub Desktop.
Some testing of the multiprocessing module in python. Trying to learn.
import multiprocessing
from multiprocessing import Pool
def say_hello(nums):
return sum([x**x for x in xrange(nums[0], nums[1])])
if __name__ == '__main__':
num_processors = multiprocessing.cpu_count()
print 'You have {0:1d} CPUs'.format(num_processors)
nums = [(0, 1000), (1000, 2000), (2000, 3000), (3000, 4000)]
pool = Pool(processes=num_processors)
count = pool.map(say_hello, nums)
print sum(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment