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-159964: Propagate contextvars to ThreadPoolExecutor tasks by methatp0 · Pull Request #160024 · python/cpython

Conversation

@methatp0

@methatp0 methatp0 commented Oct 21, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Fixes gh-159964.

Capture a copy of the submitting thread's context for each submitted task and execute the callable within that context. This prevents a task from inheriting stale context from whichever worker happened to start first and keeps context-variable rebinding in one task isolated from subsequent tasks.

The change includes a regression test for context propagation across reused workers, documentation, and a NEWS entry.

Validation: lint and the C API documentation check pass. The full CI matrix is running; the local CPython test suite could not be run in this environment.

Sorry, something went wrong.

Uh oh!

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

All reactions
@python-cla-bot

python-cla-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

  • [email protected]

CLA not signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app

bedevere-app Bot commented Oct 21, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

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

@methatp0 methatp0 changed the title Fix ThreadPoolExecutor context propagation gh-159964: Propagate contextvars to ThreadPoolExecutor tasks Oct 21, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 21, 2026
ThreadPoolExecutor tasks see the context of whichever submit() call started their worker thread #159964
Open
@methatp0
pythongh-159964: Propagate contextvars to ThreadPoolExecutor tasks
526dfe8
@methatp0
methatp0 force-pushed the fix-threadpool-contextvars-submit branch from 8731f40 to 526dfe8 Compare October 21, 2026 05:25
@methatp0
methatp0 marked this pull request as ready for review October 21, 2026 05:25
@bedevere-app bedevere-app Bot added the awaiting review label Oct 21, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 21, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35288083 | 📁 Comparing 526dfe8 against main (b577a54)

  🔍 Preview build  

2 files changed
± library/concurrent.futures.html
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

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

@ngoldbaum

ngoldbaum commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Thanks for the patch. I was planning to work on this issue, and I’ll take it from here. The proposed change fixes the reproducer, but unconditional context propagation also changes downstream behavior. I want to think about compatibility questions and performance before settling on an implementation. I’m closing this PR to avoid parallel work; I’ll follow up on the issue.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ngoldbaum ngoldbaum closed this Oct 21, 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

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

ThreadPoolExecutor tasks see the context of whichever submit() call started their worker thread

Uh oh!

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

2 participants

@methatp0 @ngoldbaum
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.