Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It stopped working #168

Open
Nemecsek opened this issue Jan 26, 2023 · 2 comments
Open

It stopped working #168

Nemecsek opened this issue Jan 26, 2023 · 2 comments

Comments

@Nemecsek
Copy link

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?

@bandoos
Copy link

bandoos commented Feb 2, 2023

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!

@Nemecsek
Copy link
Author

Nemecsek commented Feb 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants