python中通过类的方式创建线程
1 import threading 2 import time 3 4 class MyThread(threading.Thread): 5 def __init__(self,num): 6 threading.Thread.__init__(self) 7 self.num=num 8 def run(self):# 定义每个线程要运行的函数 9 print("running on number:%s"% self.num) 10 time.sleep(3) 11 12 if __name__=='__main__': 13 t1=MyThread(1) 14 t2=MyThread(2) 15 t1.start() 16 t2.start()