Streamlit App crashing after few minutes of usage

I have built a multipage streamlit app that pulls data from SQL server. The app works very fine on my local system and was successfully deployed on streamlit cloud. However, after deployment, the app fails after few minutes of usage. Find the error page below;

Find the link to the deployed app on streamlit here; https://avonhmo-utilization.streamlit.app/

and here is the link to my github repo for the app;

Please I will appreciate any quick help with this issue, I have added cache and set the data run from SQL to every 24hours using the @st.experimental_memo(ttl) to avoid data the app.

I have also copied a part of the log below, the error i am getting does not contain any information that points in any direction as to what could be responsible for this.

/***/home/appuser/venv/lib/python3.9/site-packages/pandas/io/sql.py:761: UserWarning: pandas only support SQLAlchemy connectable(engine/connection) ordatabase string URI or sqlite3 DBAPI2 connectionother DBAPI2 objects are not tested, please consider using SQLAlchemy
warnings.warn(
/home/appuser/venv/lib/python3.9/site-packages/pandas/io/sql.py:761: UserWarning: pandas only support SQLAlchemy connectable(engine/connection) ordatabase string URI or sqlite3 DBAPI2 connectionother DBAPI2 objects are not tested, please consider using SQLAlchemy
warnings.warn(
[11:47:59] :exclamation: Streamlit server consistently failed status checks
[11:47:59] :exclamation: Please fix the errors, push an update to the git repo, or reboot the app. ***/

Hi @Data_Ninja,

A few things you might try:

  1. Delete and redeploy the app
  2. Upgrade to a newer version of streamlit and use st.cache_data and st.cache_resource rather than st.experimental_memo and st.cache. I don’t know if st.cache is causing the issue, but it seems like it might be.
  3. Try setting showErrorDetails = true in your config for testing purposes, to see if that shows any useful details about what is actually failing.
  4. Try to limit to only cache the functions which are actually returning either a reusable resource like a database connection, or are actually returning data.

Do you know how much data you are typically loading from the database?

both cache_data and cache_resource seems to have been deprecated. This is the error I get when I try to use either.

I remembered I tried using them when I was building and it was when I stumbled on st.experimental_memo… I have also deleted the app and redeployed.

No, you are using an old streamlit version, probably 1.16.0

1 Like

I have updated my streamit to the latest version 1.20.0, and I have been able to use cache_data. But I noticed the app crashes anytime more than one user attempt to use the app. This error persist;

Can anyone at least give me an idea why this is happening?? The error log does not provide much information to work with.

Have a look at these examples how to use a database connection together with caching:

Thank you for your help so far, I have read all these documentation and it still does not provide any new information to help resolve this error.

I will really appreciate if someone can help look through my code and identify what could be responsible for the app crashing. I need to at least know what’s causing the error so I can debug appropriately.

I can confirm that the app works fine with just 2 users, the app crashes once a third user attempt to use the app. Could this be related to resource limit on the streamlit app??
I just need to be certain if it’s a resource limit issue or if there are some adjustments I can do to my algorithm to fix this issue. Please help.

I have confirmed that the problem with the app crashing with multiple users is because I did not not use session_state to ensure that the computations are not calculated with each run. I have been trying to add session_state to my code but I keep getting KeyError: 'st.session_state has no key ".

Can anyone help to add session_state to my code ??? Please

Hi @Data_Ninja,

The typical pattern with session_state is something like this:

  1. Initialize the entry in st.session_state to some default value, if it hasn’t been set yet:
if "some_key" not in st.session_state:
    st.session_state["some_key"] = None # Or whatever default value you want
  1. Update the session state if something happens
if user_submitted_thing is not None:
    st.session_state["some_key"] = user_submitted_thing
  1. Use that value from session state
data = get_data(thing=st.session_state["some_key"])

The order and details of 2 and 3 will vary, but typically those are the three thing you will do – first initialize the value, update it in certain conditions, and use the value directly from session state

Hello,

Just following up with this thread as I think a current problem I have might be somewhat relevant to this thread.

I have an app that has been working fine for a while now, except it has been needing to be rebooted frequently, ever since I made one change to a line that filtered the data, so that less data was being excluded. The app still functions as it should besides the semi-frequent crashes (once to a few times per day).

I am wondering what might be the cause of this? Is there a certain size limit to data that makes the app reboot? To me it seems unlikely to be this because it works fine most of the time, but curious what some possible explanations might be.

Appreciate any help that could be provided.

@Data_Ninja did you ever find out what the problem was?

@Tommy_Ruppert The issue with my app most likely was due to the amount of data i was pulling and it appears the streamlit cloud has a resource limitation in this regard. I deployed my app on the azure app service instead of the streamlit cloud and since then, my app has been working very fine even with multiple users. I hope this response helps.

1 Like

That does help, I will look into those options. Thanks!