-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample7.py
More file actions
39 lines (24 loc) · 721 Bytes
/
Copy pathexample7.py
File metadata and controls
39 lines (24 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import threading
import time
from timeit import default_timer as timer
def thread_a():
print("Thread A is starting...")
print("Thread A is performing some calculation...")
time.sleep(2)
print("Thread A is performing some calculation...")
time.sleep(2)
def thread_b():
print("Thread B is starting...")
print("Thread B is performing some calculation...")
time.sleep(5)
print("Thread B is performing some calculation...")
time.sleep(5)
thread1 = threading.Thread(target=thread_a)
thread2 = threading.Thread(target=thread_b)
start = timer()
thread1.start()
thread2.start()
thread1.join()
thread2.join()
print("Took %.2f seconds." % (timer() - start))
print("Finished.")