threading Python · 常用模块
让程序同时运行多个线程,适合 IO 等待型任务。
怎么用
import threading
小例子
import threading
def hi():
print('hi')
t = threading.Thread(target=hi)
t.start()
t.join()
运行结果
hi
提醒:多线程共享内存,注意数据竞争。
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条