Stqdm.pandas.progress_apply(): app freezes if interrupted

Hello, Streamlit community! Desparately need your help here.
I’ve got the following code:

import streamlit as st
from time import sleep
import pandas as pd
import numpy as np
from stqdm import stqdm

def something_heavy(x):
sleep(1)
return x * 100

df = pd.DataFrame(np.random.randint(0, 100, size=(10, 2)), columns=list(‘AB’))

stqdm.pandas(desc=‘Doing smth heavy’)
df[‘C’] = df.progress_apply(lambda row: something_heavy(row[‘A’]), axis=1)
st.write(df)

I need to perform some heavy operation with the dataframe and make the app user see the progress.

The bar looks fine and shows the progress correctly. But if the app is somehow interrupted (for example, the browser tab is closed) before the progress_apply finishes, the app will get into an infinite loop on the next run. The only thing that helps in this case is rebooting the app (restaring the console).

I’ve tried using st.session_state and various other things but nothing works. Does anybody know any solution to this?

Hi @SmadeX ,

Thanks for using stqdm.
This seems to be related to this issue:

Are you on windows? Can you test the lock trick in the response? It looks like the issue with the interaction between tqdm & streamlit that happens mainly on windows.

Thank you!

Adding these 2 lines of code on top of the script did help!

from threading import RLock
stqdm.set_lock(RLock())

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