forked from anhtuank7c/learn-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample01.py
More file actions
55 lines (38 loc) · 966 Bytes
/
Copy pathexample01.py
File metadata and controls
55 lines (38 loc) · 966 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import multiprocessing
import time
def print_cube(num: float) -> None:
"""
function to print cube of given num
Parameters:
- num: float
Returns:
- None
"""
print("Simulate some work for cube")
time.sleep(10)
print(f"Cube: {num * num * num}")
def print_square(num: float) -> None:
"""
function to print square of given num
Parameters:
- num: float
Returns:
- None
"""
print("Simulate some work for square")
time.sleep(15)
print(f"Square: {num * num}")
if __name__ == "__main__":
# creating processes
p1 = multiprocessing.Process(target=print_square, args=(10,))
p2 = multiprocessing.Process(target=print_cube, args=(13,))
# starting process 1
p1.start()
# starting process 2
p2.start()
# wait until process 1 is finished
p1.join()
# wait until process 2 is finished
# p2.join()
# both processes finished
print("Done")