We notice there is interference while using standard libraries across sessions. We noticed this in the random and matplotlib libraries in our project.
We reproduce this error with this snippet of code :
Please run two sessions (open two windows or browsers with the same app) and click on start such that both apps run simultaneously.
import streamlit as st import random button1 = st.button("Start") if button1: random.seed(1) for i in range(100000000): random.random() st.write(random.random())
When we run them independently, the apps run as expected. But, when there is overlap or while the app is run on both sessions simultaneously, there is interference. This can be seen in the changed value of the write. Even Matplotlib library has a similar issue while trying to plot.
This is a workaround for the code discussed above such that even with overlapping computation or simultaneous run, the returned answer is identical.
import streamlit as st import random button1 = st.button("Start") if button1: i=0 for i in range(500000): random.seed(i) random.random() random.seed(i) st.write(random.random())
This workaround involves constant re-setting of the seed value. Please advise.