3.创建线程的第二种写法,继承threading.Tread类,重写run方法

#创建线程的第二种写法
#1.自定义一个类
#2.继承Thread
#3.重写run()方法
import threading,time,random

class MyThread(threading.Thread):
    def run(self):
        for i in range(3):
            time.sleep(random.random())
            print('~~~~~')

if __name__ == "__main__":
    print("主线程开始执行")
    #实例化一个线程
    t = MyThread()
    t.start()
    print("我是主线程当中的代码")
原文地址:https://www.cnblogs.com/zhangboblogs/p/8627461.html