python - Dash 应用程序在加载服务器后重新执行早期缓存步骤
问题描述
当我启动我的 Dash 应用程序时,我会执行一系列一次性任务 - 提取我需要的数据等。但是,Dash 似乎执行了两次:一次是我要求他们在脚本中发生,并且在加载服务器后第二次发生。
这是我正在谈论的一个简单示例:
module_link_test_source.py
print("Source module")
def source_module_function():
print("Source function")
return 1
module_link_test_destination.py
import module_link_test_source as source
import dash
import dash_html_components as html
print("Destination module")
app = dash.Dash(__name__)
function_run = source.source_module_function()
app.layout = html.Div()
if __name__ =='__main__':
app.run_server(debug=True)
当我运行时python module_link_test_destination.py
,这是控制台吐出的内容:
Source module
Destination module
Source function
Dash is running on http://127.0.0.1:8050/
* Serving Flask app "module_link_test_destination" (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
Source module
Destination module
Source function
我只希望这些print()
语句每个都执行一次。如何使这些步骤只发生一次?
解决方案
我相信您会看到这种行为,因为您正在调试模式下运行。尝试debug=False
在run_server
通话中设置。
推荐阅读
- swift - Swift MacOS - 与 MacOS 应用程序外部通信
- react-native - React Native Stack 导航屏幕不存在
- orm - PRISMA:在更新方法中的 where 子句上出现类型错误
- python - ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)
- c# - 防止 CreateDesktop 被打开
- node.js - 在 async 函数中等待而无需在sails mongo db中尝试和捕获
- spring - 在 WebClient 的 ExchangeFilterFunction 中使用 RequestContextHolder
- python-3.x - Python3 ValueError:使用请求包时的初始化选项无效
- python - 文件处理、字典和地图
- java - 音乐循环在 java android 中无法正常工作