很多同行说到python,都认为它没有多线程的实现。我之前也这样认为,但心血来潮,还是百度了一下,然后就看到了关于python多线程编程的资料。
一个简单的小例子:
import threading class threadOne(threading.Thread): name=None def __init__(self,name): threading.Thread.__init__(self) self.name=name def say(self): print("你好") def run(self) -> None: self.say() class threadTwo(threading.Thread): def say(self): print("嗨") if __name__=='__main__': one=threadOne("你") one2 = threadOne("好") one3 = threadOne("啊") two=threadTwo() li=[] li.append(one) li.append(two) one3.start() #one.say() print( one.name) print(one2.name) print(one3.name)