Python实战之多线程编程threading.Thread时间:2021-06-12 20:41:08在Python中可以使用继承threading.Thread类来实现多线程编程,其中子类可以重写父类的__init__和run方法来实现用户线程的逻辑,如下是一个简单的多线程类实现 import threadingclass MyThread(threading.Thread): def __init__(self, name=None): threading.Thread.__init__(self) self.name = name def run(self): print self.namedef test(): for i in range(0, 100): t = MyThread("thread_" + str(i)) t.start()if __name__=='__main__': test()