I have a loop inside a thread which should display 2 warnings, but it displays only one

I am running this code. It will run a loop inside another thread. When the value is even, it will display one warning, when its odd, it will display another warning. But it displays only 1 warning message.

import threading
import streamlit as st
from streamlit.runtime.scriptrunner import add_script_run_ctx
import time

def find():
    l=0
    while True:
       if l%2 == 0:
           
           st.warning('App is being updated')
       else:
           st.warning('App can be used')
       l=(l+1)%2
       time.sleep(2)
       

st.header('Basic Threading')  
t1 = threading.Thread(target = find)
add_script_run_ctx(t1)

t1.start()
import threading
import streamlit as st
import time

def find():
    l = 0
    placeholder = st.empty()
    while True:
        if l % 2 == 0:
            placeholder.warning('App is being updated')
        else:
            placeholder.warning('App can be used')
        l = (l + 1) % 2
        time.sleep(2)

st.header('Basic Threading')  
t1 = threading.Thread(target=find)

t1.start()

st.empty() creates an empty placeholder, and placeholder.warning() is then used to update the warning message within the loop.

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