PEP 489 is clear that extension modules implementing multi-phase init are expected to support use in multiple interpreters. However, there are two situations where that mandate isn't sufficient:
- PEP 684 introduces a per-interpreter GIL, where there is an additional thread-safety constraint beyond support for multiple interpreters
- the HPy project implies modules with multi-phase init but not necessarily supporting multiple interpreters
In both cases a new module def slot (the same one, in fact) is a correct solution.
For per-interpreter GIL, PEP 684 specifies that we must add a module def slot for opting in to supporting per-interpreter GIL.
For HPy, the situation was pointed out to me by @hodgestar during a conversation at PyCon.
CC @encukou
I propose the following solution:
- add a new
Py_mod_multiple_interpreters module def slot
- interpret the value to indicate support for multiple interpreters and for per-interpreter GIL
- call
_PyImport_CheckSubinterpIncompatibleExtensionAllowed() when appropriate in PyModule_FromDefAndSpec2()
The slot value may be one of the following:
0 - does not support multiple interpreters (for HPy)
1 - supports multiple interpreters (the default)
2 - supports per-interpreter GIL
It would probably make sense to define a constant (macro) for each of those.
Linked PRs
PEP 489 is clear that extension modules implementing multi-phase init are expected to support use in multiple interpreters. However, there are two situations where that mandate isn't sufficient:
In both cases a new module def slot (the same one, in fact) is a correct solution.
For per-interpreter GIL, PEP 684 specifies that we must add a module def slot for opting in to supporting per-interpreter GIL.
For HPy, the situation was pointed out to me by @hodgestar during a conversation at PyCon.
CC @encukou
I propose the following solution:
Py_mod_multiple_interpretersmodule def slot_PyImport_CheckSubinterpIncompatibleExtensionAllowed()when appropriate inPyModule_FromDefAndSpec2()The slot value may be one of the following:
0- does not support multiple interpreters (for HPy)1- supports multiple interpreters (the default)2- supports per-interpreter GILIt would probably make sense to define a constant (macro) for each of those.
Linked PRs