Last active
January 14, 2018 10:23
-
-
Save santosh/6289455999e5690d79e7772f32117231 to your computer and use it in GitHub Desktop.
Starting threads. #2
This file contains hidden or 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 | |
def calc_square(numbers): | |
print("calculate square numbers") | |
for n in numbers: | |
time.sleep(0.2) | |
print('square', n*n) | |
def calc_cube(numbers): | |
print("calculate cube numbers") | |
for n in numbers: | |
time.sleep(0.2) | |
print('cube', n*n) | |
arr = [2, 3, 8, 9] | |
t = time.time() | |
t1 = threading.Thread(target=calc_square, args=(arr,)) | |
t2 = threading.Thread(target=calc_cube, args=(arr,)) | |
t1.start() | |
t2.start() | |
t1.join() | |
t2.join() | |
print("done in: ", time.time() - t ) | |
print("Hah.. I am done with all my works now!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment