接口内容:重启moco server
@app.route('/moco/restart',methods=['POST'])
def restart_moco():
try:
port=request.form['port']
except:
port=9999
if port==None or port=='':
port=9999
os.system("kill `ps -ef|grep moco|grep -v grep| awk '{print $2}'`")
rs=os.system("nohup java -jar moco/moco-runner-0.12.0-standalone.jar http -p {} -g moco/settings.json >/dev/null 2>&1 &".format(port))
if rs==0:
json = {
"code": 200,
"status": "success",
"message": "重启成功"
}
return jsonify(json)
else:
json = {
"code": rs,
"status": "fail",
"message": "重启失败,请尝试修改端口重试"
}
return jsonify(json)
使用Manager启动flask app无任何异常
使用nginx+uwsgi+flask的部署方式,此接口基本超时.
上服务器直接执行curl显示Terminate

其余接口无异常,分析此接口与其余接口的特殊之处只有调用了系统命令
将os.system换成subprocess.call("kill `ps -ef|grep moco|grep -v grep| awk '{print $2}'`", shell = True)后解决问题
没深层次查找原因,但是解决了问题,待空了再来研究研究
本文介绍了一种解决在使用nginx+uwsgi+Flask部署环境下,特定接口频繁超时的问题。通过将os.system替换为subprocess.call,成功解决了因调用系统命令导致的接口响应延迟。
4438

被折叠的 条评论
为什么被折叠?



