Python 多进程、多线程启动
作者:互联网
本文仅供学习交流使用,如侵立删!联系方式及demo下载见文末 |
Python 多进程启动
def main(self, num):
"""
多进程启动
ValueError: Pool not running:这个问题的根源在于:pool.close()提前生效,关闭了pool。所以提示pool没有运行。
解决:多层循环的情况下,将pool.close()
pool.join()
写在循环最外层
"""
# 多进程启动
pool = Pool(num)
# 获取首字母品牌名称,车系代号
for brand in self.get_brand():
for vehicleId, brandType, carName in self.get_model(brand=brand):
# 启动进程
pool.apply_async(self.run, (brand, vehicleId, brandType, carName))
pool.close()
pool.join()
Python 多线程启动
def main(self):
# 获取首字母品牌名称,车系代号
for brand in self.get_brand():
print(brand)
t_list = []
for vehicleId, brandType, carName in self.get_model(brand=brand):
print(vehicleId, brandType, carName)
t = threading.Thread(target=self.run, args=(brand, vehicleId, brandType, carName))
t_list.append(t)
# 启动线程
for t in t_list:
t.start()
# 等待所有线程结束
for t in t_list:
t.join()
本文仅供学习交流使用,如侵立删! 企鹅 、WX: 1033383881(备注来意) |
标签:vehicleId,Python,brand,carName,brandType,进程,多线程,self,pool 来源: https://blog.csdn.net/qq_38154948/article/details/113934394