threads = []
for id in idlist:
t = threading.Thread(target=process_main,args=(id,result))
threads.append(t)
for t in threads:
t.start()
for t in threads:
t.join() #等待每一个线程执行完成 join所完成的工作就是线程同步,即主线程任务结束之后,进入阻塞状态,一直等待其他的子线程执行结束之后,主线程再终止
print("finished")
python实现for循环多线程执行
本文介绍了如何在Python中使用`threading.Thread`创建和管理线程,包括创建新线程、调用`start()`启动线程和使用`join()`实现线程同步,确保主线程在所有子线程完成后才结束。


被折叠的 条评论
为什么被折叠?



