I’m trying to send a request to an external API, wait some time and get back the response. Here’s a minimal example of my code (I replaced the requests with just logs):
import streamlit as st from time import sleep @st.cache def run(): print('Send some request and wait some time') sleep(5) print('Request the response') if __name__ == '__main__': run()
When I run it (
streamlit run app.py), the output is:
Send some request and wait some time Send some request and wait some time Request the response Request the response
In other words, it is executing the function twice, which shouldn’t happen. I notice the problem goes away when I remove the
sleep (but of course I need it for my app to run properly).