#!/usr/bin/env python # Python program to illustrate the concept # of threading # importing the threading module # import threading import time def print_cube(num): """ function to print cube of given num """ print("Starting Cube...") print("sleeping in print_cube") time.sleep(5) print("Cube: {}".format(num * num * num)) def print_square(num): """ function to print square of given num """ print("Starting Square...") print("sleeping in print_square") time.sleep(10) 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=(3,)) # starting thread 1 t1.start() # starting thread 2 t2.start() # wait until thread 1 is completely executed t1.join() print("... done joining thread 1...") # wait until thread 2 is completely executed t2.join() print("... done joining thread 2...") # both threads completely executed print("Done!")