Commit 7e1d0f40 authored by 张彦钊's avatar 张彦钊

add multi-process

parent 650e2992
...@@ -225,25 +225,31 @@ def pipe_line(queue_name, queue_arg, device_id): ...@@ -225,25 +225,31 @@ def pipe_line(queue_name, queue_arg, device_id):
return diary_queue return diary_queue
def user_update(device_id,city_id,data_set_cid): def user_update(device_id, city_id, queue_name,data_set_cid):
queue_name_list = ["native_queue","nearby_queue","nation_queue","megacity_queue"] queue_list = get_queue(device_id, city_id, queue_name)
for queue_name in queue_name_list: if queue_list:
queue_list = get_queue(device_id, city_id,queue_name) queue_predict = list(set(queue_list) & set(data_set_cid))
if queue_list: queue_not_predict = list(set(queue_list) - set(data_set_cid))
queue_predict = list(set(queue_list) & set(data_set_cid)) queue_arg = [queue_predict, queue_not_predict, queue_list]
queue_not_predict = list(set(queue_list) - set(data_set_cid)) if queue_predict != []:
queue_arg = [queue_predict, queue_not_predict, queue_list] diary_queue = pipe_line(queue_name, queue_arg, device_id)
if queue_predict != []: if diary_queue:
diary_queue = pipe_line(queue_name, queue_arg, device_id) update_sql_dairy_queue(queue_name, diary_queue, device_id, city_id)
if diary_queue: print("更新结束")
update_sql_dairy_queue(queue_name, diary_queue, device_id, city_id)
print("更新结束")
else:
print("获取的日记列表是空,所以不更新日记队列")
else: else:
print("预测集是空,不需要预测") print("获取的日记列表是空,所以不更新日记队列")
else: else:
print("日记队列为空") print("预测集是空,不需要预测")
else:
print("日记队列为空")
def mult_iproecess_update(device_id, city_id, data_set_cid):
queue_name_list = ["native_queue","nearby_queue","nation_queue","megacity_queue"]
pool = Pool(4)
for queue_name in queue_name_list:
pool.apply_async(user_update, (device_id, city_id, queue_name,data_set_cid,))
pool.close()
pool.join()
def run(): def run():
...@@ -252,7 +258,7 @@ def run(): ...@@ -252,7 +258,7 @@ def run():
for device_city in device_city_list: for device_city in device_city_list:
start = time.time() start = time.time()
user_update(device_city[0], device_city[1],data_set_cid) mult_iproecess_update(device_city[0], device_city[1], data_set_cid)
end = time.time() end = time.time()
print("更新该用户队列耗时{}秒".format((end-start))) print("更新该用户队列耗时{}秒".format((end-start)))
print("end") print("end")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment