Configuring Session-State Updates for Concurrent Requests in Streamlit
0 reputation · 04 May 2020, 12:58 UTC
Goal: Ensure that updates to Streamlit’s per‑user session state remain atomic when multiple browser tabs issue simultaneous requests, avoiding latency spikes caused by the GIL.
Constraint: Streamlit provides no built‑in locking mechanism for the shared in‑memory session‑state dictionary; developers must introduce external synchronization primitives, but the appropriate scope and placement of such locks are not documented, and improper use can lead to deadlocks or unnecessary contention.
Uncertainty: It is unclear whether a single global lock around all session‑state mutations is sufficient, or whether fine‑grained locks per key yield better performance without risking race conditions.
What lock granularity is recommended for session‑state updates? Should developers adopt a single global lock or per‑key locks, and how can they verify that latency spikes are eliminated without introducing deadlock?