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



WRITTEN BY
hojongs
블로그 옮겼습니다 https://hojongs.github.io/