You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New threads should inherit the contextvars.Context of their creator #128555
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
+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.
Activity
rhettinger commentedon Jan 8, 2025
My mental model for context vars is that they operate similarly to
thread.local()and that it would be surprising if they didn't.StanSvec commentedon Jan 9, 2025
+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.
kumaraditya303 commentedon Jul 18, 2025
This is now implemented as
thread_inherit_contextflag.