GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@Liam-DeVoe Liam-DeVoe commented Jan 30, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • Issue: contextlib.redirect_stdout/stderr does not work with pytest-run-parallel #130148

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Liam-DeVoe
add redirect_stdout(..., per_thread: bool = False)
bf55f48
@bedevere-app bedevere-app Bot mentioned this pull request Jan 30, 2026
contextlib.redirect_stdout/stderr does not work with pytest-run-parallel #130148
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Jan 30, 2026
@Liam-DeVoe
Liam-DeVoe marked this pull request as draft January 30, 2026 06:12
@bedevere-app bedevere-app Bot removed the awaiting review label Jan 30, 2026
@picnixz

picnixz commented Jan 31, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@picnixz picnixz added the pending The issue will be closed if no feedback is provided label Feb 1, 2026
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 5, 2026
@ambv

ambv commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv closed this Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

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.

Projects

None yet

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.

3 participants

@Liam-DeVoe @picnixz @ambv
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.