Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from multiprocessing import Process, Queue
- def do_sum(q,l):
- res = 0
- for i in range(10000):
- res += sum(l)
- q.put(res)
- def main():
- my_list = range(1000000)
- cores = 8
- n = len(my_list) / cores
- chunks = (my_list[i:i+n] for i in xrange(0, len(my_list), n))
- q = Queue()
- ps = [Process(target=do_sum, args=(q, chunk))
- for chunk in chunks]
- print len(ps)
- for p in ps:
- p.start()
- print sum(q.get() for p in ps)
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement