-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusingThreads.py
More file actions
44 lines (29 loc) · 909 Bytes
/
Copy pathusingThreads.py
File metadata and controls
44 lines (29 loc) · 909 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
#!usr/bin/python
import threading
import time
exitFlag = 0
class mythread(threading.Thread):
def __init__(self, threadName, delay):
self.threadName = threadName
self.delay = delay
threading.Thread.__init__(self)
def run(self):
print "starting:" + self.threadName
print_time(self.threadName, self.delay, 5)
print "exiting " + self.name
def print_time(threadName, delay, counter):
while counter:
if exitFlag:
thread.exit()
time.sleep(delay)
print "%s %s" %(threadName, time.ctime(time.time()))
counter-=1
t_1 = mythread("thread-1", 2)
t_2 = mythread("thread-2", 2)
t_1.start()
t_2.start()
while not t_1.isAlive():
if not t_2.isAlive():
exitFlag = 1
pass
print "exiting the main thread"