Skip to content

Instantly share code, notes, and snippets.

@shankcode
Last active April 26, 2017 16:26
Show Gist options
  • Save shankcode/310ed9160ed16ca9826d65cd15cdbfb6 to your computer and use it in GitHub Desktop.
Save shankcode/310ed9160ed16ca9826d65cd15cdbfb6 to your computer and use it in GitHub Desktop.
Finding Square and cube using Multi-threading
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