Streamlit application runs multiple times on startup

Hey everyone,

in the application I’m currently working on I observe that the program runs multiple times on startup. This behavior even occurs when starting the simplest possible program (print statement is executed multiple times):

import streamlit as st

print("new run")

When refreshing the page, the print statement is executed once (as expected).

I’m using

  • streamlit 1.27.2 (running on localhost)
  • Python 3.9.17

Is there any solution for this “bug”/problem?

Thank you!

1 Like

I can’t reproduce the issue with Streamlit v1.29.0, so maybe upgrading would fix it for you.

1 Like

Thank you for your answer. Upgrading to v1.29.0 unfortunately didn’t solve the issue. The amount of program runs is random, sometimes the program runs once after starting (as expected) but sometimes it runs twice or more often.

1 Like

I tried multiple times and each time the script ran only once. We must be doing something different from each other but I don’t know what it can be. Can you reproduce the issue in streamlit cloud?

1 Like

Do you mean Streamlit Community Cloud? When deploying an app there, is there an opportunity to see e.g. print statements? Because otherwise I won’t see if the programs runs multiple times (it has no visual effect, I just see this behavior in the console).

1 Like

Ah! Looks like you cannot just print to the console in streamlit community cloud, but you can use os.write instead.

1 Like

I have the same issue. After a bit of debugging it appears that the dashboard runs twice on startup, on two different threads concurrently (thread ids are different).

I’m using streamlit==1.31.1

1 Like