search

Home  >  Q&A  >  body text

python - Flask script, no response after running for a while

code show as below:

# -*- coding:utf-8 -*-
import flask
import subprocess

app = flask.Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

@app.route("/api/clear",methods=['POST'])
def clear():
    domains = flask.request.form
    for k in domains:
        if domains[k].strip() != '':
            #os.system('rm -rf /data/proxy_cache_dir/'+ domains[k])
            subprocess.call('rm -rf /data/proxy_cache_dir/' + domains[k], shell=True)

    return domains['domain']

@app.route("/apinew/clear",methods=['POST'])
def new_clear():
    domains = flask.request.form
    for k in domains:
        if domains[k].strip() != '':
            #os.system('rm -rf /data/proxy_cache_dir/'+ domains[k])
            subprocess.call('rm -rf /data/proxy_cache_dir/' + domains[k], shell=True)

    return domains['0']

if __name__ == "__main__":
    app.run(host='0.0.0.0',port=5000)

This is the same piece of code that has been running well on a previous server. Now running on Baidu Cloud Server, it will become unresponsive after a while, so you need to shut down the process and run it again. Before the subprocess.call method, using os.system will have the same problem, and the normal running time will be shorter. I hope you guys can give me some advice on where to start.

曾经蜡笔没有小新曾经蜡笔没有小新2826 days ago2231

reply all(1)I'll reply

  • 迷茫

    迷茫2017-05-18 10:58:36

    1. Did an exception occur here?
    2. Did this command run successfully?

    reply
    0
  • Cancelreply