Error using st.cache

Hi, I am getting this error while running my app.

hash function via the hash_funcs keyword in @st.cache(). For example:
xpecta_1 |
xpecta_1 | xpecta_1 | @st.cache(hash_funcs={_io.TextIOWrapper: my_hash_func}) xpecta_1 | def my_func(...): xpecta_1 | ... xpecta_1 |
xpecta_1 |
xpecta_1 | If you don’t know where the object of type _io.TextIOWrapper is coming
xpecta_1 | from, try looking at the hash chain below for an object that you do recognize,
xpecta_1 | then pass that to hash_funcs instead:
xpecta_1 |
xpecta_1 | ```

The function that is generating the error is this one:

@st.cache(ttl=28800)
def upload_data():
################################ CONNECTION TO MYSQL ################################

try:
    db = mysql.connector.connect(host=os.getenv('DB_HOST'),database=os.getenv('DB_NAME'),user=os.getenv('DB_USER'),password=os.getenv('DB_PASSWORD'))
    if db.is_connected():
        db_Info = db.get_server_info()
        logger.info(f"Connected to MySQL Server version {db_Info}")
        
        df=pd.read_sql(query,db)

except Error as e:
    logger.error(f"Error while connecting to MySQL: {str(e)}")
finally:
    if db.is_connected():
        db.close()
        logger.info("MySQL connection is closed")

return df

Hi! Did you try with st.experimental_memo?

1 Like

Hi , I tried this but didn’t work.

This happen when I run streamline in a Virtual Machine. I don’t know the os of the virtual machine right now but the experimental_memo and experimental_singleton did’nt work. I downgrade the streamlit version to 1.8.1 and then it works.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.