fix: make threads share their accumulated output#8418
Merged
Conversation
Represent empty output as an empty list, and never the object bound to it; child threads need to share the parent thread's output object, which is not possible if mo.output* methods set it to None.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates marimo’s imperative output plumbing so mo.Thread instances share the spawning cell’s accumulated output container, enabling safe multi-thread appends and preventing thread output from being wiped when the parent cell completes. It also adds thread-safety to mo.status.progress_bar updates.
Changes:
- Introduce
CellOutputList, a thread-safe container for imperative cell outputs, and make it the default forExecutionContext.output. - Update
mo.output.*internals, kernel output caching, and post-exec output broadcast logic to work withCellOutputList. - Make progress bar updates thread-safe and add runtime + smoke tests covering threaded output scenarios.
Reviewed changes
Copilot reviewed 12 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/_runtime/test_threads.py | Adds coverage ensuring threads share the parent cell’s output container. |
| tests/_runtime/test_cell_output_list.py | Adds unit tests for CellOutputList behavior. |
| marimo/_smoke_tests/threads/threads.py | Smoke test for stdout redirection with threading.Thread vs mo.Thread. |
| marimo/_smoke_tests/threads/state_threading.py | Smoke test exercising state updates from a background mo.Thread. |
| marimo/_smoke_tests/threads/progress_bar_threads.py | Smoke test for progress bar updates from multiple threads. |
| marimo/_smoke_tests/threads/multiple_appends.py | Smoke test for concurrent append/replace output patterns with threads. |
| marimo/_smoke_tests/status/status.py | Adds status component smoke coverage (progress bars/spinners). |
| marimo/_smoke_tests/output.py | Updates output smoke test formatting + includes replace-at-index usage. |
| marimo/_runtime/threads.py | Shares parent ExecutionContext.output into thread execution contexts. |
| marimo/_runtime/runner/hooks_post_execution.py | Adjusts output broadcast condition to use CellOutputList truthiness. |
| marimo/_runtime/output/_output.py | Refactors imperative output ops to use CellOutputList methods and stack(). |
| marimo/_runtime/context/types.py | Makes ExecutionContext.output a non-optional CellOutputList via default_factory. |
| marimo/_runtime/cell_output_list.py | New thread-safe output container implementation. |
| marimo/_runtime/app/kernel_runner.py | Updates cached-output handling to stack CellOutputList. |
| marimo/_plugins/stateless/status/_progress.py | Adds locking around progress updates for thread-safety. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
@coastalwhite this should generally improve your experience of writing to output from multiple threads (including with progress bars)
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR makes
mo.Threads share their creating cell's accumulated output list. This improves the experience of imperatively writing output with threads in two ways:To accommodate this, this PR abstracts away the underlying list of imperative outputs, and instead introduces a thread-safe container that manages access to the outputs data structure.
This change also makes
mo.status.progress_barthread-safe.Follow up to #8413