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):
#curl_atlas.execute("select path from seetaAtlas.model where id='%s'" % modelid)
db_l = Mysql_lock()
err_msg = "get wrong params file"
if db_l.db == '':
return None,None
return None,None,err_msg
#lock_name = 'db_queue'
#ret = db_l.lock(lock_name,10)
#if ret != True:
......@@ -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)
if ret is None:
return None,None
return None,None,err_msg
result_atlas = db_l.cursor.fetchall()
......@@ -82,13 +83,13 @@ def get_path_from_db(modelid,seetanet_model):
if len(result_atlas) != 1:
logging.info('get wrong mxnet model path')
return None,None
return None,None,err_msg
else:
path_name = str(result_atlas[0])
if path_name.find("|") == -1:
if path_name.find("::") == -1:
logging.info('get wrong parameters!')
return None,None
return None,None,err_msg
else:
path_list = path_name.split("::")
......@@ -123,13 +124,15 @@ def get_path_from_db(modelid,seetanet_model):
if(stbf_down(params_name_path,download_path)):
logging.info("download params file: %s success" % params_name)
else:
return None,None
err_msg = "download file failed"
return None,None,err_msg
#download file from fastdfs
if(stbf_down(graph_name_path,download_path)):
logging.info("download params file: %s success" % graph_name)
else:
return None,None
err_msg = "download file failed"
return None,None,err_msg
#post return progress
GP.set_progress_var(10)
......@@ -138,10 +141,11 @@ def get_path_from_db(modelid,seetanet_model):
#Driver converter model by params and model graph
result = Run_Converter(params_name,graph_name,seetanet_model)
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)
return params_name,graph_name
return params_name,graph_name,err_msg
def upload_filetoFastDFS(params_name, graph_name,seetanet_model):
#upload seetanet file to fastdfs
......@@ -172,19 +176,23 @@ def get_info_from_queue(arg):
GP.set_err_msg_var("")
err_msg = ""
GP.set_post_type_var(return_flag)
seetanet_model = "model_" + str(modelid) + ".data"
params_name = ""
graph_name = ""
try:
#post return progress
#GP.set_progress_var(10)
#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:
logging.info("get wrong params file")
err_msg = "get wrong params file"
#err_msg = "get wrong params file"
return_flag = "error"
else:
stmodel_fid = upload_filetoFastDFS(params_name, graph_name,seetanet_model)
......@@ -244,6 +252,18 @@ def get_info_from_queue(arg):
GP.set_progress_var(0)
#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()
t = threading.Thread(target=get_info_from_queue,args=(1,))
......
......@@ -389,8 +389,10 @@ class Converter(object):
length = np.array(len(ss), np.int64)
fo.write(length.tobytes())
fo.write(ss)
return True
except Exception, e:
GP.set_err_msg_var(repr(e))
return None
finally:
fo.close()
......@@ -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:
return None
graph = load_graph(model_json)
if graph is None:
logging.info('load graph failed!!!')
return None
converter = Converter(graph, arg_params, aux_params)
logging.info('start to convert model parameters')
converter.convert(seetanet_model)
logging.info('convert success!!!')
result = converter.convert(seetanet_model)
if result != True:
logging.info('convert net failed!!!')
return None
logging.info('convert net success!!!')
return True
except Exception, e:
return None
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!