# 直接实例化创建 from threading import Thread def sayhi(name): n=100 for i in range(n): print('%s say hello%d ' % (name,i)) if __name__ == '__main__': t = Thread(target=sayhi, args=('egon',)) t.start() print('主线程 ')
===================================
# 直接实例化创建 # 继承Thread类创建方式 from threading import Thread class Sayhi(Thread): def __init__(self, name): super().__init__() self.name = name def run(self): n=100 for i in range(n): print('%s say hello %d ' % (self.name,i)) if __name__ == '__main__': t = Sayhi('egon') t.start() print('主线程')