python多线程问题
程序代码:
from threading import Lock, Thread import time class Test(): def __init__(self): self.countFlag = 0 self.testList = [] self.lock = Lock() for i in range(10000): self.testList.append(i) def pt(self, name): print(name) while self.countFlag < len(self.testList): self.lock.acquire() print(self.testList[self.countFlag]) # time.sleep(1) self.countFlag += 1 self.lock.release() if __name__ == "__main__": test = Test() thdList = [] for i in range(5): t = Thread(target=test.pt, args=("线程" + str(i) + '\n',)) t.setDaemon(True) thdList.append(t) t.start() for t in thdList: t.join()
线程1执行输出了一个0,其他线程都没输出,后面就线程4一直输出;请教一下 为啥只有一个线程在执行?哪里的问题?