I have a python script that sometimes I run by streamlit run myscript.py and other times I run by python myscript.py. How can the script detect whether it was invoked by streamlit?
I want to do a simple conditional.
if {launchedbystreamlit}:
st.error("error message")
else:
print("error message")
Help me think this through…
streamlit run foo.py or
python foo.py
in foo.py:
–are there any streamlit processes running on this machine?
– are any of those st processes running foo.py?
Thet feels too complicated and fragile to me. It would be easier to query the state of the streamlit module (or some submodule). Unfortunately there is no public API for this as far as I know. The closest thing would be using _get_websocket_headers()
. It is not public but there’s at least the promise of trying not to accidentally break it, which is more than what you get by using any other internal name. It curretly returns None
if you script is running standalone.
Close enough!
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.