5.1.12 创建子线程的两种方式
方式一:
from threading import Thread def work(name): print('%s 子线程在运行。。。。' % name) if __name__ == '__main__': t1 = Thread(target=work, args=('thread1',)) t1.start() print('主线程。。。。')
方式二:
from threading import Thread class MyThread(Thread): def __init__(self, name): super().__init__() self.name = name def run(self): print('%s 子线程在运行。。。。。。' % self.name) if __name__ == '__main__': t1 = MyThread('thread_1') t2 = MyThread('thread_2') t1.start() t2.start()