-
Notifications
You must be signed in to change notification settings - Fork 5
/
threading.py
35 lines (31 loc) · 913 Bytes
/
threading.py
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
import threading
import datetime
def print_cube(num):
"""
function to print cube of given num
"""
print("Cube: {}".format(num * num * num))
def print_square(num):
"""
function to print square of given num
"""
print("Square: {}".format(num * num))
if __name__ == "__main__":
# creating thread
t1 = threading.Thread(target=print_square, args=(11,))
t2 = threading.Thread(target=print_cube, args=(3,))
print(datetime.datetime.now())
# starting thread 1
t1.start()
print(datetime.datetime.now())
# starting thread 2
t2.start()
print(datetime.datetime.now())
# wait until thread 1 is completely executed
t1.join()
print(datetime.datetime.now())
# wait until thread 2 is completely executed
t2.join()
print(datetime.datetime.now())
# both threads completely executed
print("Done!")