아래와 같이 적용할 수 있다.
자세한 내용은 링크를 참조한다.
from multiprocessing import Process, Queue import time def do_work(start, end, result): sum = 0 for i in range(start, end): sum += i result.put(sum) return if __name__ == "__main__": t1 = time.time() START, END = 0, 80000000 result = Queue() th1 = Process(target=do_work, args=(START, int(END/2), result)) th2 = Process(target=do_work, args=(int(END/2), END, result)) th1.start() th2.start() th1.join() th2.join() result.put('STOP') sum = 0 while True: tmp = result.get() if tmp == 'STOP' : break else: sum += tmp t2 = time.time() - t1 print("Result : ", sum) print("Time : ", t2)