Skip to content
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

[RFC] Implement PEP 567 (contextvars) #3188

Closed
Tracked by #5104 ...
fanninpm opened this issue Oct 2, 2021 · 0 comments · Fixed by #5300
Closed
Tracked by #5104 ...

[RFC] Implement PEP 567 (contextvars) #3188

fanninpm opened this issue Oct 2, 2021 · 0 comments · Fixed by #5300
Labels
RFC Request for comments

Comments

@fanninpm
Copy link
Contributor

fanninpm commented Oct 2, 2021

Summary

The contextvars module, from PEP 567, is necessary to upgrade asyncio (and decimal) to CPython 3.8. I started #2950 to implement contextvars, but the PR has since stalled. (@DimitrisJim urged me to open this issue.)

Detailed Explanation and Rationale

PEP 567, implemented in CPython 3.7, introduced the contextvars module and context variables, which are conceptually similar to thread-local variables. However, unlike thread-local variables, context variables correctly support asynchronous code. Following that implementation, the asyncio and decimal modules were re-written to take advantage of this new capability. As part of our endeavors to get as much of the codebase covered by the CPython test suite as possible (see #1671), and out of a desire support CPython 3.8 or later (see the README), I think it's necessary to add the test_asyncio module to the CPython test suite. The addition of the CPython 3.8 version of test_asyncio would benefit from upgrading the asyncio module itself to that same version. (@coolreader18 and I have noticed that test failures were often alleviated by upgrading the relevant Python module.) However, asyncio has a dependency — contextvars — that we don't have yet. Accordingly, I have started a draft PR (#2950) to implement this module here, but I got stymied when I was drafting the Rust implementation because I am unfamiliar with how RustPython deals with thread safety. For context, here are the parts of the C implementation that I think are relevant:

Unresolved Questions

  • What is the meaning of PyContext (defined in pyobject.rs), and does it have any bearing on the scope of PEP 567?
  • The scaffolding is present, but how should it be fleshed out?
  • How would each Context object relate to a thread in RustPython?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request for comments
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant