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)後解決問題

沒深層次查找原因,但是解決了問題,待空了再來研究研究

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