【发布时间】:2018-03-31 20:56:05
【问题描述】:
您好,我有一个用 Flask 编写的 Web 应用程序,它连接到 USB 信用卡刷卡器。 swiper 的代码是用 java 编写的,我的烧瓶应用程序是这样的
@app.route("/swipe")
def index():
a = Popen(["sudo", "java", "sample"], shell=False)
sts2 = os.waitpid(p.pid, 0)
return "hello"
@app.route("/kill_swiper", methods=["POST"])
def index_2():
try:
pid = request.json
pid = pid.get("pid")
os.kill(int(pid), signal.SIGTERM)
return Response(json.dumps({"status": True}), status=200, mimetype='application/json')
except Exception as e:
print(e)
return Response(json.dumps({"status": False}),
status=417, mimetype='application/json')
if __name__ == '__main__':
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.run(host="0.0.0.0")
每当用户单击按钮时,都会触发刷卡器,将他重定向到他可以刷卡或单击取消的页面。
谈到我的问题,我可以通过运行命令从外部杀死 swiper
sudo kill <pid of swiper>
但是当我尝试点击网站上的取消按钮时,它并没有被杀死。我在 gunicorn 后面运行烧瓶应用程序,我正在使用以下命令运行 gunicorn
sudo gunicorn --bind 0.0.0.0:5000 --workers 3 app:app
我尝试提供线程作为选项,但它不起作用。谁能告诉我哪里出错了
【问题讨论】:
标签: python python-3.x flask gunicorn