-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
new thread doesn't copy context of the parent thread #86981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
New thread doesn't copy context of the parent thread. The minimal example to reproduce the issue:
Is it expected behavior? PEP-567 I didn't find anything regarding this case. |
Trust me, it's too late to fix this in 3.10. |
As I read PEP-567, it looks like contextvars were not intended to be automatically copied into new threads. One of the examples describes how to use a copy of the current thread's context vars in another thread: https://peps.python.org/pep-0567/#offloading-execution-to-other-threads Furthermore, It is a bit surprising that scheduling an tl;dr I think this is working as intended, and we can close this issue. (But I agree that the behavior is bit surprising.) |
Thanks for doing this research; I agree that we can close this. I don't want to speculate on the reasons for starting a new thread with an empty context; maybe it was an oversight, maybe it was being strict in the layering of dependencies (contexts depend on threads, so threads shouldn't depend on contexts), maybe it was something else. Maybe Yury could tell us, but he's got bigger things on his mind. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: