flask执行系统命令的接口超时

接口内容:重启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)后解决问题

没深层次查找原因,但是解决了问题,待空了再来研究研究

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章