Skip to content

Commit de04d86

Browse files
author
krsm
committed
refactoring processes code
1 parent e38a6f9 commit de04d86

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

Multiprocessing/processes.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,34 @@
22
"""
33
Simple study related to Multiprocessing
44
5-
"""
5+
"""
6+
7+
import os
8+
from multiprocessing import Process
9+
10+
#function 1
11+
def calculate_square(n):
12+
print('calculated square:', n*n)
13+
proc = os.getpid()
14+
print('{0} process id:'.format(proc))
15+
16+
17+
#function 2
18+
def calculate_cube(n):
19+
print('calculated cube:', n*n*n)
20+
proc = os.getpid()
21+
print('{0} process id'.format(proc))
22+
23+
24+
if __name__ == "__main__":
25+
26+
numbers = [1, 2, 3, 4, 5]
27+
procs = []
28+
29+
for index, n in enumerate(numbers):
30+
p = Process(target=calculate_square, args=(n,))
31+
procs.append(p)
32+
p.start()
33+
#
34+
# for proc in procs:
35+
# proc.join()

0 commit comments

Comments
 (0)