bpo-44050: Extension modules can share state when they don't support sub-interpreters. by shihai1991 · Pull Request #27794 · python/cpython

LGTM, but can you try to write an unit test?

Would it be possible to write an unit test for this? https://bugs.python.org/issue44050 is a regression. It would be better to not reintroduce it by mistake tomorrow.

Maybe using the ssl module: if if it's already imported, skip the test. Otherwise, spawn a subinterpreter to import it, and then import it in the main interpreter, and compare if you get the same objects or not.

See wee-slack/wee-slack#812 (comment) for a more complete example.

To make sure that the ssl module is not imported yet, you can run the test in a subprocess, eg. using assert_python_ok(), or subprocess.