import threading
import time
class MyThread(threading.Thread):
def run(self):
for i in range(3):
time.sleep(1)
msg = "I'm " + self.name
print(msg)
def sayPoem(self):
print("衰荷滚玉闪晶光,一夜西风一夜凉。"
"雁阵声声蚊欲静,枣红点点桂流香。")
def sayGood(self):
print("Let's not forget from whence we came.")
if __name__ == '__main__':
t = MyThread()
t.start()
t.sayPoem()
t.sayGood()
线程写了start开始运行,start会一定调run
通过类的方式开启线程,不需要写sayPoem, sayGood,只需要写前面就好了。
run这个方面是继承于父
但在这个测试中发现如果像上面这样,则run会最后执行,为什么?类的对象先执行自己的最后执行继承的????