forked from PacktPublishing/AdvancedPythonProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample7.py
More file actions
38 lines (25 loc) · 738 Bytes
/
example7.py
File metadata and controls
38 lines (25 loc) · 738 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
# ch12/example7.py
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.')