-
Notifications
You must be signed in to change notification settings - Fork 4k
Make our Python Altair code thread-safe #12673
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
Conversation
✅ PR preview is ready!
|
8bb886b to
b930161
Compare
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR makes Streamlit's Altair chart handling code thread-safe by wrapping thread-unsafe operations in a threading lock. The main issue addressed is that Altair's global variables for themes and data transformers were being modified concurrently, causing empty charts when multiple charts were rendered simultaneously in different threads.
- Introduces a threading lock to protect Altair global state modifications
- Refactors the data transformer function to be a standalone module-level function
- Updates comments to reflect the new transformer function name
kmcgrady
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Things LGTM overall. I agree with testing. I remember we had some e2e tests failing likely due to this scenario, but we must have found a workaround on the tests. We do mark some as flaky so perhaps we can test drive removing it, but that seems like a separate initiative.
Co-authored-by: Copilot <[email protected]>
Describe your changes
Today, our Altair-handling code in Python does some things that modify global variables in the
altairmodule differently for each chart, which makes the code thead-unsafe. This leads to empty charts whenever two charts are drawn at the same time in different threads.This PR addresses that by wrapping the thread-unsafe code into a
threading.Lock, plus a couple of small refactors.GitHub Issue Link (if applicable)
none
Testing Plan
Unit Tests (JS and/or Python)E2E TestsAny manual testing needed?Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.