streamlit-server-state icon indicating copy to clipboard operation
streamlit-server-state copied to clipboard

It stopped working

Open Nemecsek opened this issue 2 years ago • 2 comments

With this demo code I was able to make some experiments, but then it stopped working completely. I restarted the browser, tried with different browsers, restarted the app, removed the lock but nothing works anymore and the browsers is in an infinite loop tills it crashes.

import streamlit as st
from streamlit_server_state import server_state, server_state_lock

with server_state_lock["u1"]:
    if "u1" not in server_state:
        server_state.u1 = 0
        
server_state.u1 = server_state.u1 + 1

st.write(server_state.u1)

Traceback is

2023-01-26 13:02:04.236 Uncaught app exception
Traceback (most recent call last):
  File "/home/alex/PycharmProjects/test_bluelikon_client_streamlit/venv/lib/python3.8/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script
    exec(code, module.__dict__)
  File "/home/alex/PycharmProjects/test_bluelikon_client_streamlit/singleuser.py", line 12, in <module>
    st.write(server_state.u1)
  ...
  File "/home/alex/PycharmProjects/test_bluelikon_client_streamlit/venv/lib/python3.8/site-packages/streamlit/runtime/scriptrunner/script_requests.py", line 157, in on_scriptrunner_yield
    return ScriptRequest(ScriptRequestType.RERUN, self._rerun_data)
  File "<string>", line 3, in __init__
RecursionError: maximum recursion depth exceeded while calling a Python object

Any idea?

Nemecsek avatar Jan 26 '23 12:01 Nemecsek

I think that what happens here (because of streamlit's - in this case streamlit_server_state - refresh logic) is that any time the script runs, the increment line is executed, which in mutates the server state and makes all pages reload (since server state has in fact changed), thus the st.write code is in practice dead code!

bandoos avatar Feb 02 '23 17:02 bandoos

I assume it is guaranteed that before page reload the current page is executed completely, so the st.write should be executed too.

Nemecsek avatar Feb 03 '23 08:02 Nemecsek