【发布时间】:2022-01-10 08:29:10
【问题描述】:
在 Plotly Dash 中,我正在尝试
- 确定我是否在调试模式下运行,并且
- 仅当应用程序未在调试模式下运行时,才将日志处理程序更改为 SMTPHandler
我尝试了什么:
import dash
app = dash.Dash(__name__)
if app.server.debug is False:
print("Not in Debug mode")
# app.logger.addHandler(mail_handler)
if __name__ == '__main__':
app.run_server(debug=True, use_reloader=True)
print(f"app.server.debug is {app.server.debug}") # This code only executes after the server is shut down
我试过app.server.debug(和app.server.config["DEBUG"]),但都返回False。所以我无法确定应用程序是否实际上处于调试模式。
这是我的控制台输出:
Not in Debug mode Dash is running on http://127.0.0.1:8050/ * Serving Flask app 'example_code' (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Debug mode: on Not in Debug mode
我认为这种混淆是因为未设置 FLASK_DEBUG 环境变量,但即便如此,它确实会显示 * Debug mode: on 那么如何在运行时识别它?
最后,我应该在哪里添加此调试模式检查并更改处理程序 - 调试在 app.run_server() 中设置,但之后立即添加任何代码仅在服务器关闭后执行。
【问题讨论】:
标签: python flask plotly plotly-dash python-logging