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 — New threads should inherit the contextvars.Context of their creator · Issue #128555 · python/cpython

New threads should inherit the contextvars.Context of their creator #128555

New issue
Copy link
New issue
Copy link
Closed
Closed
New threads should inherit the contextvars.Context of their creator#128555
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@nascheme
nascheme
opened on Jan 6, 2025
Issue body actions

Feature or enhancement

Proposal:

It would be convenient and likely less surprising if threads inherited the context of their creator, rather than starting with an empty context. This would match what asynio.Task does. This has been requested before, as gh-86981.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/thread-safe-warning-filters/

Linked PRs

  • gh-128555: Add 'context' keyword parameter to Thread. #128209
Reacted by Stan Svec, Raphaël Cohen, Hugo Elias Berg and Nikita Reznikov

Activity

  1. nascheme
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Jan 6, 2025
  2. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Jan 6, 2025
  3. rhettinger commented on Jan 8, 2025

    @rhettinger
    rhettinger
    on Jan 8, 2025
    Contributor
    More actions

    It would be convenient and likely less surprising if threads inherited the context of their creator, rather than starting with an empty context.

    My mental model for context vars is that they operate similarly to thread.local() and that it would be surprising if they didn't.

    Reacted by Robert Schmidtke
  4. StanSvec commented on Jan 9, 2025

    @StanSvec
    StanSvec
    on Jan 9, 2025
    More actions

    +1 on this idea. When a parent task needs to split work into concurrent subtasks, having access to the same context just makes sense. I can't see any real downsides to doing this, but I can think of many cases where inherited context would be helpful.

  5. kumaraditya303 commented on Jul 18, 2025

    @kumaraditya303
    kumaraditya303
    on Jul 18, 2025
    Contributor
    More actions

    This is now implemented as thread_inherit_context flag.

  6. kumaraditya303
    closed this as completedon Jul 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.