Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow writing to Streamlit from multiple threads #315

Open
tvst opened this issue Oct 8, 2019 · 1 comment
Open

Allow writing to Streamlit from multiple threads #315

tvst opened this issue Oct 8, 2019 · 1 comment
Labels
area:threading/processing type:enhancement Requests for feature enhancements or new features

Comments

@tvst
Copy link
Contributor

tvst commented Oct 8, 2019

See a possible solution here: https://gist.github.com/tvst/fa33b9dcb58040cbcb0ea376146d4e8c
and see https://discuss.streamlit.io/t/live-plot-from-a-thread/247 for context.

A few thoughts on that Gist:

  1. Can we make that API match the one from st? That is, it would be great if methods from the main DeltaGenerator were accessible as thread_safe_st.foo rather than from thread_safe_st.main.foo
  2. Even better, can the user just pass the st object itself to the other thread? Why do we need ThreadSafeSt at all?
  3. If it turns out that a ThreadSafeSt is needed, we should come up with a better name for it. Something likeStreamlitContext sounds good to me, but we already have a ReportContext in our codebase, so it may be confusing. Maybe rename ReportContext in the process?

Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

@tvst tvst added type:enhancement Requests for feature enhancements or new features spec needed labels Oct 8, 2019
@caspark
Copy link

caspark commented Oct 16, 2019

Seems like it's pretty straightforward to address point 2 by extending ThreadSafeSt like this:

class ThreadSafeSt():
    # ... original class body

    def __getitem__(self, item):
        return self.main[item]

    def __getattr__(self, item):
        return getattr(self.main, item)

Haven't tested it extensively, but it seems to work well enough for my purposes!

@jrieke jrieke added the status:unlikely Will probably not implement but looking for further feedback label Feb 10, 2023
@jrieke jrieke removed the status:unlikely Will probably not implement but looking for further feedback label Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:threading/processing type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

No branches or pull requests

5 participants