Why global code runs twice

In my dash application, there are some pre-processing where I initialize some variables. The codes are placed before app = das.Dash() line. See example.

def get_big_dataframe():
perform a large query.
x = get_big_dataframe()
app = dash.Dash()

However, when I run the app, before starting the server it executes the line x = get_big_dataframe() twice. Do you know why it executes twice? How can I prevent it to execute twice?

2 Likes

This is how flask debugger works. You can set debug=False to prevent this, but then you’ll miss out on the live reloading.

5 Likes

Thanks!
Now I understand the reason. :slight_smile: