Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b3b9d9b

Browse files
Create square_cube.py
1 parent adad23a commit b3b9d9b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

‎scripts/square_cube.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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!")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /