Displaying Streamlit spinning wheel until a file exists

Hi,

I wanted to display something like this: st.spinner(text=“Wait for Results…”) for an unknown time period. I want to run the spinner until a file doesn’t exist in my local system, which is getting created meanwhile by another python program.

Best,
Debayan

Can’t you do something along the lines of:

import streamlit as st
import os.path
import time

file_exists = os.path.exists('readme.txt')
with st.spinner('Wait for it...'):
    while not file_exists:
      st.write(f"""file exists: {file_exists}""")
      # do nothing
      time.sleep(1)
      file_exists = os.path.exists('readme.txt')
st.success('Done!')

Or is there something more?

Hi @willhuang, sorry for the delayed reply. I had a mistake in the original question, which I am unable to edit. My file is getting created by the ‘same’ streamlit program, notanother’ program. Using your code thus makes it stuck in an infinite while loop, unfortunately because in that icase it never escapes the loop.

So just creating the file inside the with statement should do. Doesn’t it?

Thanks @Goyo , that indeed worked! Not needed to write the while loop