1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | def func(q, start, interval): result = 0 for i in range(start, start+interval): result += i q.put(result) proc_cnt = 4 q_list = [] proc_list = [] output = 0 start = 0 interval = int(1000000000 / proc_cnt) # process create & start for i in range(proc_cnt): q = Queue() p = Process(target=func, args=(q, start, interval)) p.start() start += interval q_list.append(q) proc_list.append(p) # receive output from processes for q in q_list: temp = q.get() # print(temp) output += temp print(output) # vs single-processing result = 0 for i in range(1000000000): result += i print(result) | cs |
'Language > python' 카테고리의 다른 글
[python] scrapy with form-data (0) | 2018.03.23 |
---|---|
python scrapy 한글 인코딩 (0) | 2018.03.16 |
[Language] [IDE] PyCharm Run Path (Working Directory) (0) | 2018.01.05 |
[python] tornado package (0) | 2018.01.01 |
[python] ctypes: ARRAY vs POINTER 차이/비교 (0) | 2018.01.01 |
WRITTEN BY
- hojongs
블로그 옮겼습니다 https://hojongs.github.io/