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!

2 Likes

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

Just to say that the issue still happens with 1.36.0
At First launch, the page is run many times, sometimes 7 times.
When refreshing the browser page, only one run as expected.

Still happening on

1.37.1

I’m wondering if this is a session state issue.

I run into the same issue in my local development environment: The PID of the process is the same, but the code is executed by three different threads.
I usually start the application as follows:

python -m streamlit run app/viewer.py

python version: 3.10.2
streamlit version: 1.39.0
OS. Ubuntu 22.04.4 LTS

did’nt work

Whenever you press Ctrl+C to stop the application, make sure to close inactive tabs that are open in your browser. This issue occurs because when you run the application, old tabs refresh, resulting in the same number of new runs being printed as the total number of Streamlit windows opened in the browser.