Warning for missing ScriptRunContext

Hi to all…when i am running my streamlit app in Pycharm i get this warning

missing ScriptRunContext! This warning can be ignored when running in bare mode.

other than this warning appearing in the terminal 100 times the app works fine…
can anyone explain why this warning occurs…
Thanks in advance

Bumping this. Very annoying, but app (in my case, a test) works fine.

I’ve tried suppressing the logging with logging.getLogger('streamlit').setLevel(logging.ERROR) but it doesn’t help.

Any ideas?

What if you run it without pycharm?

are you running it in a jupyter notebook?

I’m running it in VSCode so it’s not exclusive to the IDE you’re using. I wish I could at least learn what “bare mode” even means.

Alright I think I’ve got my case figured out at least. This is what worked for me:

from streamlit.runtime.scriptrunner import add_script_run_ctx,get_script_run_ctx
from subprocess import Popen

ctx = get_script_run_ctx()
##Some code##
process = Popen(['python','my_script.py'])
add_script_run_ctx(process,ctx)

My interpretation of the error is that streamlit does not like streamlit function calls outside the main controlling script, so if you launch your script with streamlit run script.py and try to use st.write or other functions in another script that the main script.py calls using multithreading or subprocess, then we get the error. To suppress the error, we just need to add it to the context to make streamlit happy again. The documentation only refers to multithreading, but subprocess also works for me. I’m not sure if multiprocess would have similar behavior, but in theory I think it would. I have not tested it though.

Lots of people seem to be trying (myself included) only add_script_run_ctx(process) without much success. For me, the key was I needed to also supply the ctx to which it would add the script, so that’s why we instantiate it at the top of the script. After that, you just add the script to the context manager like we’ve been trying in order to suppress the annoying error spam.

Further, the “bare mode” it refers to is used for script/streamlit testing without launching the script via the streamlit CLI method, so for most of us it seems we would have to deal with it eventually since we wouldn’t want to deploy in bare mode.

2 Likes

No…from the answer that Talia posted, i am assuming that i use many imports that i execute in the main script and maybe that is causing the warnings!

Hi…i actually have functions that i export and execute in the main script that return a plotly figure and then i just use st.plotly_chart to plot it…in some cases i export a function that calculates x and then use it in the function that returns the plotly figure and then i use that in the main script!

In my case, when my script starts other threads and runs streamlit functions within them, this warning appears.
When I try to avoid running st functions in other threads (including avoid running functions decorated with @st.cache_resource), this warning disappears.