Hi, I write an app which uses the ECMWF Magics (https://anaconda.org/conda-forge/magics) to produce weather analysis maps in streamlit. When one user accesses the app, it’s OK. But several users access the app at the same time, I always get the error: “Segmentation fault (core dumped)”. I think the ECMWF Magics doesn’t support multiple threadings. So I want to lock the threading when one user makes some pictures with Magics. I use the following code:
from threading import Lock
import streamlit as st
lock = Lock()
with lock:
# call the Magics functions.
image = draw_weather_analysis()
st.image(image, use_column_width=True)
But this does not worked. The “Segmentation fault (core dumped)” error still display, and I found the ‘lock’ can not lock the streamlit thread. So how can I do? Thanks very much.
As the code is run in different threads (one per user session), in your example you are just creating two different locks in each session. What you want instead is a lock shared with every session.
To do that, you could try to use @thiago’s GlobalState.
Another option is to instead make a small webapp around magics so that becomes a single threaded API. Then your streamlit app just calls out to that, no locking and hacking needed.
Hi, Synode:
Thanks for your reply very much. With the global state of “st_state_patch”, I can lock the threading and the Magics functions run correctly.
from threading import Lock
import streamlit as st
import st_state_patch
s = st.GlobalState(key="mySate")
if not s:
s.lock = Lock()
with s.lock:
# call the Magics functions.
image = draw_weather_analysis()
st.image(image, use_column_width=True)
Sorry for warming up that thread again, but is there still a global state implementation available? I would need it also for locking (in that case matplotlib).
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.