docs icon indicating copy to clipboard operation
docs copied to clipboard

add doc to explain multithreading

Open jokester opened this issue 1 year ago • 4 comments

Warning for interested

This PR likely requires major change before merged, if it ever will. The patterns mentioned should mostly work for current Streamlit, but the official team has the decide to how to introduce them.

📚 Context

Surprising many people are confused by multithreading in Streamlit, like in https://github.com/streamlit/docs/issues/87 / https://github.com/streamlit/streamlit/issues/1326 / https://github.com/streamlit/streamlit/issues/8490 .

This PR tries to explain the underneath Streamlit-specific things, and provide multithreading patterns to start with.

🧠 Description of Changes

  • Add a page to explain Streamlit-created and user-created threads, and how to use them together.

Revised:

see the new file

Current:

(I didn't find document explaining threads and ScriptRunContext, except in the code)

💥 Impact

Size:

  • [ ] Small
  • [x] Not small

🌐 References

  • https://github.com/streamlit/docs/issues/87
  • https://github.com/streamlit/streamlit/issues/1326
  • https://github.com/streamlit/streamlit/issues/8490

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

jokester avatar Sep 17 '24 15:09 jokester

I'm happy to hear feedback about content or format :pray:

jokester avatar Sep 18 '24 14:09 jokester

CI fails but I can't find the error message. The links like https://app.netlify.com/sites/streamlit-docs/deploys/66eaa4a1b1871d000843e854 only says "A fatal rendering error has occurred"

jokester avatar Sep 18 '24 14:09 jokester

Hi @jokester. Thanks for contributing. The site won't build and the page won't be viewable without correctly updating site navigation. Check out the readme file for docs, specifically Add pages to the menu.

I'm going over items for the next release right now, so it might take me a few weeks to look at this more closely. Multithreading has been on my list for a while, so thanks for taking a stab at it. I'll circle back here when I get the next release fleshed out. 😄

sfc-gh-dmatthews avatar Sep 18 '24 23:09 sfc-gh-dmatthews

@sfc-gh-dmatthews Thanks !! I managed to get preview build to work https://deploy-preview-1154--streamlit-docs.netlify.app/develop/concepts/architecture/threading

jokester avatar Sep 19 '24 04:09 jokester

Sorry for the delay. I've been working on this this week. I think instead of the pseudo code to explain the threading structure, an illustration might be better. I have a much more detailed illustration I want to put into a contributing wiki-type document, but for this guide, I want to make sure it's as accessible to Python developers as possible (who might not ever touch a Tornado server to deal with WebSockets). I'm currently thinking of something like this to just schematically show script threads tied to script runs and that they have to communicate both to the front end and the server.

image

I should have the PR updated with a first pass by early next week. 😄

sfc-gh-dmatthews avatar Dec 14 '24 01:12 sfc-gh-dmatthews