Last active
April 26, 2017 16:26
-
-
Save shankcode/310ed9160ed16ca9826d65cd15cdbfb6 to your computer and use it in GitHub Desktop.
Finding Square and cube using Multi-threading
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 | |
import time | |
arr =[2, 4, 6, 8, 9] | |
def calc_square(number): | |
for n in number: | |
num = n*n | |
print('Square of ' + str(n) + ' is ' + str(num)) | |
#time.sleep(2) | |
print('\n') | |
def calc_cube(number): | |
for n in number: | |
num = n*n*n | |
print('Cube of ' + str(n) + ' is ' + str(num)) | |
#time.sleep(0.2) | |
t1 = threading.Thread(target= calc_square, args= (arr,)) | |
t2 = threading.Thread(target= calc_cube, args= (arr,)) | |
t1.start() | |
t2.start() | |
t1.join() | |
t2.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment