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()