01 线程的两种创建方式
from threading import Thread # from multiprocessing import Process # def f1(n): # print('%s号线程任务'%n) # def f2(n): # print('%s号线程任务'%n) # if __name__ == '__main__': # t1 = Thread(target=f1,args=(1,)) # t2 = Thread(target=f2,args=(2,)) # t1.start() # t2.start() # print('主线程') #第二种创建方式 class MyThread(Thread): def __init__(self,name): # super(MyThread, self).__init__() super().__init__() self.name = name def run(self): print('hello girl :' + self.name) if __name__ == '__main__': t = MyThread('alex') t.start() print('主线程结束')