-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
gh-117398: datetime: Access C-API via PyInterpreterState
#118357
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
Include/datetime.h
Outdated
static PyDateTime_CAPI *(*_get_pydatetime_capi)(void) = _get_pydatetime_capi_dummy; | ||
#define PyDateTimeAPI _get_pydatetime_capi() | ||
|
||
static inline void pydatetime_import(void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to not leak such implementation detail at the ABI level, and so use a regular function rather than a static inline function. I would prefer that _pydatetime_capi is private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I resolve non-Windows errors? I'm not sure how to use private struct members here.
Error: _testcapi failed to import: /home/runner/work/cpython/cpython-builddir/
build/lib.linux-x86_64-3.13-pydebug/_testcapi.cpython-313d-x86_64-linux-gnu.so:
undefined symbol: _PyDateTimeAPI_Get
I added another capsule which points to the |
Such change is too late for beta1. It's better to wait for the beginning of the 3.14 dev cycle. |
How do you think of the situation? |
In my experience, such change is likely to cause regression and need more time to be stabilized. I prefer to wait Wednesday. |
Otherwise, 3.13 should take specific workarounds for the crash |
A workaround is ready for review: #118531 |
Which crash? This PR is related to issue gh-117398 which doesn't mention any crash. |
FYI, I asked @Yhg1s if we could get an exception for landing this after beta 1: #103092 (comment). He gave us a similar exception for 3.12. Thomas might not do that this time, but at least I've asked. |
This particular change is just one that adds a new capsule C API, which can then be used when in the future the datetime module switches to multi-phase init and better subinterpreter support, right? Given that it's of mild impact and it gives us an API that allows us to deprecate the old one and use multi-phase init for datetime, I'm okay with this going into beta 2. |
It doesn't sound safe to me to announce that the _datetime extension is compatible with subinterpreters before static types are converted to heap types. I suggest to discuss the plan in the issue: #117398 (comment) |
@vstinner I think this should be tested from 3.13.0b1+. The change is easy to diagnose or revert. If an inevitable problem is found, the case will support your exceptional approach (mix EDIT: Ultimately, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO Py_MOD_PER_INTERPRETER_GIL_SUPPORTED cannot be added before other changes are done, such as converting static types to heap types.
I prefer to do the conversion in a different order, with multiple steps: #117398 (comment)
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
This PR does not add the flag in |
An alternative PR to #117413, which also makes the datetime C-API available to the isolated subinterpreters.
The pointer to the
PyDateTime_CAPI
struct is stored inPyInterpreterState
right after thePyCapsule_Import()
call. This version does not changeModules/_testcapi/datetime.c
for now. Also, the overhead should be even across interpreters.However, this extends thePyDateTime_CAPI
struct.cc @pganssle @vstinner @ericsnowcurrently @encukou @erlend-aasland