-
-
Couldn't load subscription status.
- Fork 459
Prevent module reinitialisation with multi-phase init #1978
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
Conversation
|
Thanks, human! |
|
Hmm, turns out this causes a problem in the coverage measurement of coverage itself. If I comment out the re-import check everything seems to work, but I need to understand more. |
|
I added the check & error as multi-phase assumes that modules are safe for subinterpreters by default. The relevant documentation is https://docs.python.org/dev/howto/isolating-extensions.html. On a cursory examination I think A |
|
This isn't about subinterpreters explicitly. The self-measurement involves deleting |
|
Sorry for the crossed wires. I was referring to this note:
Per that same section, sharing Python objects between module instances would likely cause crashes or undefined behavior.. The side effect of the explicit error is that deleting the module from Would A |
|
I'm assuming that the warning is actually about sharing mutable Python objects between instances. In my case, they are types and interned strings. This commit (8381ea7) seems good, but I welcome more experienced views. (Updated to use a mutex: 2d39c8c (Update: never mind, PyMutex_etc is new in 3.13)) |
|
This is now released as part of coverage 7.9.0. |
cc @nedbat
xref:
Changes written by a human ;-)
The ctracer module still uses static types (e.g.
CTracerType), so is not isolated and may have undefined behaviour or crashes on use in subintepreters or afterPy_Finalizecycles. Here, we raise an explicit ImportError for such cases.Also, change the
Py_GIL_DISABLEDcheck to a version check for thePy_mod_gilslot (it is only the unstable API that is guarded behindPy_GIL_DISABLED), usePyMODINIT_FUNCfor the init function, and use designated initialisers (I find them easier to read).A