这个程序有两个线程,这个程序运行一段时间后,只有一个线程打印出myid,为什么?另一个头有什么问题?
from threading import Thread
from time import sleep
class MyThread(Thread):
def __init__(self,myid):
Thread.__init__(self)
self.myid = myid
print self.myid
def run(self):
flag = True
while flag:
try:
print self.myid
sleep(0.1)
except Exception,e:
print e
flag = False
if __name__ =="__main__":
threads = []
for i in range(1,3):
t = MyThread(i)
threads.append(t)
for t in threads:
t.start()
threads[0].join()
print '1 is finished'
threads[1].join()
print '2 is finished'
print 'All finished'