File tree 1 file changed +36
-0
lines changed 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ # Python program to illustrate the concept
4
+ # of threading
5
+ # importing the threading module
6
+ import threading
7
+
8
+ def print_cube (num ):
9
+ """
10
+ function to print cube of given num
11
+ """
12
+ print ("Cube: {}" .format (num * num * num ))
13
+
14
+ def print_square (num ):
15
+ """
16
+ function to print square of given num
17
+ """
18
+ print ("Square: {}" .format (num * num ))
19
+
20
+ if __name__ == "__main__" :
21
+ # creating thread
22
+ t1 = threading .Thread (target = print_square , args = (10 ,))
23
+ t2 = threading .Thread (target = print_cube , args = (10 ,))
24
+
25
+ # starting thread 1
26
+ t1 .start ()
27
+ # starting thread 2
28
+ t2 .start ()
29
+
30
+ # wait until thread 1 is completely executed
31
+ t1 .join ()
32
+ # wait until thread 2 is completely executed
33
+ t2 .join ()
34
+
35
+ # both threads completely executed
36
+ print ("Done!" )
You can’t perform that action at this time.
0 commit comments