Skip to content

Instantly share code, notes, and snippets.

@moodoki
Created September 19, 2021 06:39
Show Gist options
  • Save moodoki/33b712a4680b30d8ab426aa032290f8e to your computer and use it in GitHub Desktop.
Save moodoki/33b712a4680b30d8ab426aa032290f8e to your computer and use it in GitHub Desktop.
Streamlit function cache threading
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