Created
September 19, 2021 06:39
-
-
Save moodoki/33b712a4680b30d8ab426aa032290f8e to your computer and use it in GitHub Desktop.
Streamlit function cache threading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
#CameraThread is a sub-class of threading.Thread | |
@st.cache(allow_output_mutation=True) | |
def get_or_create_camera_thread(): | |
for th in threading.enumerate(): | |
if th.name == 'CameraThread': | |
th.stop() | |
th.join() | |
cw = CameraThread(name='CameraThread') | |
cw.start() | |
return cw | |
cw = get_or_create_camera_thread() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment