Created
June 11, 2020 07:04
-
-
Save velotiotech/163efa366f037ac615a0d02e230914dd to your computer and use it in GitHub Desktop.
multithreading in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
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=(10,)) | |
t2 = threading.Thread(target=print_cube, args=(10,)) | |
# starting thread 1 | |
t1.start() | |
# starting thread 2 | |
t2.start() | |
# wait until thread 1 is completely executed | |
t1.join() | |
# wait until thread 2 is completely executed | |
t2.join() | |
# both threads completely executed | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment