-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
datetime extension module isolation #243
Comments
FYI, |
Intentionally reloading modules isn't forbidden usage. It's typically weird usage, but it's not forbidden. We include explicit workarounds in the import machinery so the interpreter doesn't die when extension modules using single-phase init are reloaded, and the impact of those workarounds results in behaviour similar to what @vstinner has proposed in gh-117398. The benefit of adopting an approach like the one Victor suggests in a case like this one is that it allows "support per-interpreter imports" to be separated from "generate completely new heap types when reloading the module" (in this particular case, it isn't clear the latter is actually desirable behaviour, and it is definitely backwards incompatible behaviour). The extra pointer to a substruct in |
gh-118337 fully implements:
It passes refleak bot tests where the module is reloaded for a good reason. |
As noted in python/cpython#117398 (comment), this may be a test coverage concern moreso than an SC design decision. I doubt the existing test suite explicitly covers the situation we're concerned about (a capsule or C API pointer reference acquired before the reload being used after the reload and crashing the interpreter), so even green CI may not be enough to be certain that full reload support is backwards compatible. |
I would llke an SC decision about how much a module can depend on
|
While you're correct that
Don't get me wrong, I think you've identified a genuine functional gap in the multi-phase init feature here: the existence of the capsule API means that there really should be a public C API for extension modules using multi-phase init to define and manage per-interpreter-instance state in addition to the existing support for defining per-module-instance state. While the standard library can work around this problem by making use of In the specific case of migrating
|
What's wrong with using Threading while reloading is probably a nightmare, but it's always going to be a nightmare. Ignoring that, |
If Per-module heaptypes should be enough, but |
@erlend-aasland also pointed out this past discussion of the external-resource-management variant of this problem (which leads to needing the ability to set up per-process locks rather than per-interpreter ones): https://discuss.python.org/t/a-new-c-api-for-extensions-that-need-runtime-global-locks/20668 |
Did @erlend-aasland point out that the problem applies to |
The linked discussion was not about |
Right, the specific problem in the There is a similar-but-distinct problem that comes up when managing external (non-Python) resources that don't allow reinitialisation within a single process: module reloads need to avoid reinitialising the affected external resources, and instead make them available to the reinitialised instance of the module. While the referenced thread is specifically about the external resource management variant of the problem, any public API we come up with needs to handle both cases. Getting back to the original question for the SC here though, I think it boils down to:
I think the only SC level decision here is "Is it OK to continue using the The specific case of |
While we can suggest that the new generic C-API is needed, there seems to be no individual discussion (issue) about its design related to
I think it is OK for third party modules to keep single-phase init. The migration is up to users.
What standard library extension modules are you suggesting?
You mean per-interpreter heaptypes for |
@ncoghlan, what do you think of introducing the a new (internal, for now) API, as discussed, and then adopt |
@erlend-aasland Can you explain how the discussion resolves |
I work on CPython on my spare time; I'm not paid to work on CPython. |
Then, why didn't you suggest it on your spare time? |
I don't think this is a productive line of conversation; let's drop it. |
|
If you contact me in private, I propose to discuss it with you. |
I'm here to follow SC because you don't look in good condition now to discuss it. |
There are more appropriate avenues for resolving this issue than asking for the SC to make a decision. Those include opening a new issue on the CPython tracker or commenting on an existing relevant issue, engaging in a discussion on discuss.python.org, or reaching out the the C API working group. In all such forums, please keep in mind that the Python Code of Conduct applies to all workspaces in order to keep the conversations respectful and productive. |
PEP-687 is about to be implemented to the
_datetime
module.Two approaches are proposed at present. I would like Steering Council to choose one.
(regular)
Multi-phase-init with per-module heaptypes (and C-API).
abi: Store a reference (to the C-API struct) in
PyInterpreterState
.(special)
Multi-phase-init with per-interpreter heaptypes (and C-API).
abi: Store at least 7 heaptypes' references in
PyInterpreterState
.The following shows the replacements of
_datetime
heaptypes (multi-phase init module) when runningtest_datetime
in the refleak test:The approach (2) avoids possible regressions1 caused by mixing modules with
forbiddenhacky usage23. Technically,(2) does not make sense(1) should be enough. In my opinion, unknown regressions should not be hidden by (2). Also, (2) will be a bad official example of isolation. However, there seems to be a case where maintaining (1) is not good for mental health, which is also serious.Related issue/PR: gh-117398, gh-118357
Thanks
UPDATED: a few rewords
Footnotes
https://github.com/python/cpython/issues/117398#issuecomment-2104353830 ↩
https://docs.python.org/3/howto/isolating-extensions.html#surprising-edge-cases ↩
https://docs.python.org/3/library/sys.html#sys.modules ↩
The text was updated successfully, but these errors were encountered: