Python 多线程-线程的继承
自定义类,继承 Thread,重写 run()方法
import threading import time class MyThread(threading.Thread): def __init__(self,thread_name): threading.Thread.__init__(self) self.thread_name=thread_name """重写run方法""" def run(self): time.sleep(3) print(self.thread_name) if __name__ == '__main__': t1 = MyThread('thread_1') t2 = MyThread('thread_2') t1.start() t2.start()