-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcode2.py
More file actions
39 lines (27 loc) · 790 Bytes
/
code2.py
File metadata and controls
39 lines (27 loc) · 790 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
# code2.py
import threading
import time
class Worker(threading.Thread):
def __init__(self, t):
super().__init__()
self.t = t
def run(self):
print("{} starting...".format(threading.currentThread().getName()))
time.sleep(self.t)
print("{} exiting...".format(threading.currentThread().getName()))
class Service(threading.Thread):
def __init__(self, t):
super().__init__()
self.t = t
def run(self):
print("{} starting...".format(threading.currentThread().getName()))
time.sleep(self.t)
print("{} exiting...".format(threading.currentThread().getName()))
# Creating threads
t1 = Service(5)
w1 = Worker(2)
w2 = Worker(4)
# The created threads are executed
t1.start()
w1.start()
w2.start()