On 2020-04-22 08:05, Glenn Linderman wrote:
On 4/21/2020 10:26 PM, Greg Ewing wrote:
And if I understand correctly, you won't get any nice "This module does not support subinterpreters" exception if you import an incompatible module -- just an obscure crash, probably of the core-dumping variety.
This sounds fixable: modules that support subinterpreters should set a flag saying so, and the either the load of a non-flagged module when subinterpreters are in use, or the initiation of a subinterpreter when a non-flagged module has been loaded, should raise.
There was talk about making a orthogonal flag just for opting into subinterpreter support. But what you use now as such a flag is multi-phase initialization: https://docs.python.org/3/c-api/module.html?highlight=pymodule_fromdefandspe... (Though I like the PEP 489 wording, "expected to support subinterpreters and multiple Py_Initialize/Py_Finalize cycles correctly", better than what ended up in the docs.) The simplest strategy to support subinterpreters correctly is to refuse to create the extension module more than once per process (with an appropriate error, of course).