| 12345678910111213141516171819202122232425 |
- # View more python learning tutorial on my Youtube and Youku channel!!!
- # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
- # Youku video tutorial: http://i.youku.com/pythontutorial
- import multiprocessing as mp
- def job(q):
- res = 0
- for i in range(1000):
- res += i+i**2+i**3
- q.put(res) # queue
- if __name__ == '__main__':
- q = mp.Queue()
- p1 = mp.Process(target=job, args=(q,))
- p2 = mp.Process(target=job, args=(q,))
- p1.start()
- p2.start()
- p1.join()
- p2.join()
- res1 = q.get()
- res2 = q.get()
- print(res1+res2)
|