GeezerVison is showing github.com — gh-130148: Add `redirect_stdout(..., per_thread: bool = False)` by Liam-DeVoe · Pull Request #144334 · python/cpython
Conversation
Liam-DeVoe
commented
Jan 30, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
In #130148, there was discussion of what would be required to make redirect_stdout thread-aware. #130148 (comment) proposed adding a per_thread: bool = False argument. This PR implements that argument.
To support interleaving per_thread=False and per_thread=True, this PR uses a slightly more complicated design involving walking up the stack of context managers to find the first one applicable to its thread.
As an example motivating usage, making doctest thread-safe becomes a ~one line change with this PR: https://github.com/python/cpython/compare/main...Liam-DeVoe:cpython:redirect-stdout-doctest?expand=1.
I think there's been previous discussion of whether this should live in CPython or be proven out in another project first. I don't know exactly where people have fallen on this. I opened a previous version of this code against Quansight-Labs/pytest-run-parallel#167, but after discussion with @ngoldbaum it was unclear to us that pytest-run-parallel is the right place for this to live, rather than the standard library.
cc: @ngoldbaum @colesbury
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
picnixz
commented
Jan 31, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Please open a new issue for that. I believe that we also suggested this to be outside the stdlib so I do not think we want this for now.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR is attached to gh-130148, which was closed as "not planned". Closing to cull the number of open pull requests. Do not reopen this pull request without getting a go-ahead from a triager or core developer to re-open the issue first.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
pending
The issue will be closed if no feedback is provided
stale
Stale PR or inactive for long period of time.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.