When I spin up my Dash app, I do a bunch of once-off tasks - pulling in the data I'll need, etc. However, it seems like Dash is performing them twice: once at the point I'm asking for them to happen in the script, and a second time once it's loaded the server up.
Here's a simple example of what I'm talking about:
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)
When I run python module_link_test_destination.py, here's what the console spits out:
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
I would only expect those print() statements to have executed once each. How do I make these steps only occur once?