最近使用了QThread发现了一些有趣的东西。记录一下
一个简单的例子
class test1(QThread): def __init__(self): super().__init__() self.threadId = 0 def run(self): self.threadId = self.currentThreadId() print("ttt2:", threading.currentThread()) def stop(self): self.terminate() self.wait() if __name__ == "__main__": app = QApplication(sys.argv) t1= test1() t1.start() time.sleep(1) print(threading.enumerate()) t1.stop() time.sleep(1) print(threading.enumerate()) for th in threading.enumerate(): print(th.isDaemon(), th.name, th.isAlive(),id(th), th.ident) print(threading.enumerate()) sys.exit(app.exec_())
他对应的打印
当时很奇怪我明明把 t1线程terminate了,但后续在threading.enumerate中还是打印出了该