Commit f03bdc49 by BoxuanXu

fix try except's bug

1 parent de33175f
Showing with 42 additions and 13 deletions
...@@ -59,8 +59,9 @@ def get_path_from_db(modelid,seetanet_model): ...@@ -59,8 +59,9 @@ def get_path_from_db(modelid,seetanet_model):
#curl_atlas.execute("select path from seetaAtlas.model where id='%s'" % modelid) #curl_atlas.execute("select path from seetaAtlas.model where id='%s'" % modelid)
db_l = Mysql_lock() db_l = Mysql_lock()
err_msg = "get wrong params file"
if db_l.db == '': if db_l.db == '':
return None,None return None,None,err_msg
#lock_name = 'db_queue' #lock_name = 'db_queue'
#ret = db_l.lock(lock_name,10) #ret = db_l.lock(lock_name,10)
#if ret != True: #if ret != True:
...@@ -70,7 +71,7 @@ def get_path_from_db(modelid,seetanet_model): ...@@ -70,7 +71,7 @@ def get_path_from_db(modelid,seetanet_model):
ret = db_l._execute("select path from seetaAtlas.model where id='%s'" % modelid) ret = db_l._execute("select path from seetaAtlas.model where id='%s'" % modelid)
if ret is None: if ret is None:
return None,None return None,None,err_msg
result_atlas = db_l.cursor.fetchall() result_atlas = db_l.cursor.fetchall()
...@@ -82,13 +83,13 @@ def get_path_from_db(modelid,seetanet_model): ...@@ -82,13 +83,13 @@ def get_path_from_db(modelid,seetanet_model):
if len(result_atlas) != 1: if len(result_atlas) != 1:
logging.info('get wrong mxnet model path') logging.info('get wrong mxnet model path')
return None,None return None,None,err_msg
else: else:
path_name = str(result_atlas[0]) path_name = str(result_atlas[0])
if path_name.find("|") == -1: if path_name.find("|") == -1:
if path_name.find("::") == -1: if path_name.find("::") == -1:
logging.info('get wrong parameters!') logging.info('get wrong parameters!')
return None,None return None,None,err_msg
else: else:
path_list = path_name.split("::") path_list = path_name.split("::")
...@@ -123,13 +124,15 @@ def get_path_from_db(modelid,seetanet_model): ...@@ -123,13 +124,15 @@ def get_path_from_db(modelid,seetanet_model):
if(stbf_down(params_name_path,download_path)): if(stbf_down(params_name_path,download_path)):
logging.info("download params file: %s success" % params_name) logging.info("download params file: %s success" % params_name)
else: else:
return None,None err_msg = "download file failed"
return None,None,err_msg
#download file from fastdfs #download file from fastdfs
if(stbf_down(graph_name_path,download_path)): if(stbf_down(graph_name_path,download_path)):
logging.info("download params file: %s success" % graph_name) logging.info("download params file: %s success" % graph_name)
else: else:
return None,None err_msg = "download file failed"
return None,None,err_msg
#post return progress #post return progress
GP.set_progress_var(10) GP.set_progress_var(10)
...@@ -138,10 +141,11 @@ def get_path_from_db(modelid,seetanet_model): ...@@ -138,10 +141,11 @@ def get_path_from_db(modelid,seetanet_model):
#Driver converter model by params and model graph #Driver converter model by params and model graph
result = Run_Converter(params_name,graph_name,seetanet_model) result = Run_Converter(params_name,graph_name,seetanet_model)
if result != True: if result != True:
return None,None err_msg = "convert mxnet to seetanet failed"
return None,None,err_msg
#Run_Converter("model-0015.params","model-symbol.json",seetanet_model) #Run_Converter("model-0015.params","model-symbol.json",seetanet_model)
return params_name,graph_name return params_name,graph_name,err_msg
def upload_filetoFastDFS(params_name, graph_name,seetanet_model): def upload_filetoFastDFS(params_name, graph_name,seetanet_model):
#upload seetanet file to fastdfs #upload seetanet file to fastdfs
...@@ -172,19 +176,23 @@ def get_info_from_queue(arg): ...@@ -172,19 +176,23 @@ def get_info_from_queue(arg):
GP.set_err_msg_var("") GP.set_err_msg_var("")
err_msg = "" err_msg = ""
GP.set_post_type_var(return_flag) GP.set_post_type_var(return_flag)
seetanet_model = "model_" + str(modelid) + ".data"
params_name = ""
graph_name = ""
try: try:
#post return progress #post return progress
#GP.set_progress_var(10) #GP.set_progress_var(10)
#GP.Post_return() #GP.Post_return()
seetanet_model = "model_" + str(modelid) + ".data"
params_name,graph_name = get_path_from_db(modelid,seetanet_model) params_name,graph_name,err_msg = get_path_from_db(modelid,seetanet_model)
if params_name is None or graph_name is None: if params_name is None or graph_name is None:
logging.info("get wrong params file") logging.info("get wrong params file")
err_msg = "get wrong params file" #err_msg = "get wrong params file"
return_flag = "error" return_flag = "error"
else: else:
stmodel_fid = upload_filetoFastDFS(params_name, graph_name,seetanet_model) stmodel_fid = upload_filetoFastDFS(params_name, graph_name,seetanet_model)
...@@ -244,6 +252,18 @@ def get_info_from_queue(arg): ...@@ -244,6 +252,18 @@ def get_info_from_queue(arg):
GP.set_progress_var(0) GP.set_progress_var(0)
#post_return = { "posttype": return_flag, "progress" : 0, "pool_id": pool_id, "err_msg":err_msg } #post_return = { "posttype": return_flag, "progress" : 0, "pool_id": pool_id, "err_msg":err_msg }
try:
if params_name is None or graph_name is None:
cmd_str = "rm -rf " + seetanet_model
else:
cmd_str = "rm -rf " + params_name + " " + graph_name + " " + seetanet_model
print(cmd_str)
subprocess.check_call(cmd_str,shell=True)
except subprocess.CalledProcessError as err:
logging.info("file remove error!")
GP.Post_return() GP.Post_return()
t = threading.Thread(target=get_info_from_queue,args=(1,)) t = threading.Thread(target=get_info_from_queue,args=(1,))
......
...@@ -389,8 +389,10 @@ class Converter(object): ...@@ -389,8 +389,10 @@ class Converter(object):
length = np.array(len(ss), np.int64) length = np.array(len(ss), np.int64)
fo.write(length.tobytes()) fo.write(length.tobytes())
fo.write(ss) fo.write(ss)
return True
except Exception, e: except Exception, e:
GP.set_err_msg_var(repr(e)) GP.set_err_msg_var(repr(e))
return None
finally: finally:
fo.close() fo.close()
...@@ -433,10 +435,17 @@ def Run_Converter(model_param,model_json,seetanet_model): ...@@ -433,10 +435,17 @@ def Run_Converter(model_param,model_json,seetanet_model):
if sym is None or arg_params is None or aux_params is None: if sym is None or arg_params is None or aux_params is None:
return None return None
graph = load_graph(model_json) graph = load_graph(model_json)
if graph is None:
logging.info('load graph failed!!!')
return None
converter = Converter(graph, arg_params, aux_params) converter = Converter(graph, arg_params, aux_params)
logging.info('start to convert model parameters') logging.info('start to convert model parameters')
converter.convert(seetanet_model) result = converter.convert(seetanet_model)
logging.info('convert success!!!') if result != True:
logging.info('convert net failed!!!')
return None
logging.info('convert net success!!!')
return True return True
except Exception, e: except Exception, e:
return None return None
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!