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)后解决问题

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值