故意将烧瓶倒下

时间:2018-10-09 09:49:09

标签: python flask gunicorn supervisord

要练习使用supervisor使烧瓶服务器保持活动状态,我插入了sys.exit()

import sys
from flask import Flask
app = Flask(__name__)


@app.route('/')
def hello_world():
    sys.exit()
    return 'Hello, World!'


if __name__ == '__main__':
    app.run()

通过flask run进行开发或通过gunicorn app:app进行生产时都会产生错误

This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

This site can’t be reached
localhost refused to connect.
ERR_CONNECTION_REFUSED

,但既不能关闭服务器,也不能烧瓶自行重启。发生了什么,我该如何故意关闭Flask服务器?

1 个答案:

答案 0 :(得分:0)

尝试使用class Utils { static createTargetDict(ps) { return { targets: { ...ps.targets, ...Utils.createElement(target), // this will fail bc target doesn't exist }, }; } static key() { let d, r; return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => { r = (new Date().getTime() + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16); }); } static createElement(target) { const key = Utils.key(); return { [key]: { ...target, current: { ...target.current, key: key, visibility: false, }, }, }; } } 来立即终止程序。 os._exit()引发SystemExit异常,只会杀死当前线程。