python中的线程threading.Thread()
import threading import time def saySorry(i): if int(i)%2==0: time.sleep(3) print("亲爱的,我错了,我能吃饭了吗?", str(i)) if __name__ == "__main__": for i in range(5): t = threading.Thread(target=saySorry,args=(i,)) t.start() # 启动线程,即让线程开始执行
参考:节选自 https://blog.csdn.net/qq_35423190/article/details/127060182
这里有一篇更详细的:https://juejin.cn/post/7027667024121692191