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
| import threading import time
class MyThread(threading.Thread): def __init__(self, threadID, name, delay): threading.Thread.__init__(self) self.threadID = threadID self.name = name self.delay = delay
def run(self): print "starting", self.name print_time(self.name, 5, self.delay) print "exiting", self.name
def print_time(threadName, count, delay): while count: time.sleep(delay) print "%s : %s" % (threadName, time.ctime()) count -= 1
t1 = MyThread(1, "Thread-1", 1) t2 = MyThread(2, "Thread-2", 2) t1.start() t2.start()
t2.join() print "Exiting Main!!!"
|