-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (36 loc) · 1006 Bytes
/
Copy pathmain.py
File metadata and controls
51 lines (36 loc) · 1006 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
40
41
42
43
44
45
46
47
48
49
50
51
import threading
import datetime
Flag = 0
class MyThread (threading.Thread):
def __init__(self, name, counter):
threading.Thread.__init__(self)
self.threadID = counter
self.name = name
self.counter = counter
def run(self):
print("Starting " + self.name)
threadLock.acquire()
print_date(self.name, self.counter)
threadLock.release()
print("Exiting " + self.name)
def print_date(threadName, counter):
datefields = []
today = datetime.date.today()
datefields.append(today)
print(
"%s[%d]: %s" % (threadName, counter, datefields[0])
)
threadLock = threading.Lock()
threads = []
thread1 = MyThread("Thread", 1)
thread2 = MyThread("Thread", 2)
thread3 = MyThread("Thread", 3)
thread1.start()
thread2.start()
thread3.start()
threads.append(thread1)
threads.append(thread2)
threads.append(thread3)
for t in threads:
t.join()
print("Exiting the Program!!!")