[New-bugs-announce] [issue40600] Add an option to disallow creating more than one instance of a module

STINNER Victor report at bugs.python.org
Mon May 11 18:12:29 EDT 2020


New submission from STINNER Victor <vstinner at python.org>:

When a C extension module is created with PyModuleDef_Init(), it becomes possible to create more than one instance of the module.

It would take significant effort to modify some extensions to make their code fully ready to have two isolated module.

For example, the atexit module calls _Py_PyAtExit() to register itself into the PyInterpreterState. If the module is created more than once, the most recently created module wins, and calls registered on other atexit instances are ignore: see bpo-40288.

One simple option would be to simply disallow loading the module more than once per interpreter.

Also, some extensions are not fully compatible with subinterpreters. It may be interesting to allow to load them in a subinterpreter if it's not already loaded in another interpreter, like another subinterpreter or the main interpreter. It would be only load it once per Python *process*. For example, numpy would be a good candidate for such option.

I'm not sure fow a module should announced in its definition that it should not be loaded more than once.

----------
components: Extension Modules
messages: 368665
nosy: corona10, eric.snow, vstinner
priority: normal
severity: normal
status: open
title: Add an option to disallow creating more than one instance of a module
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40600>
_______________________________________


More information about the New-bugs-announce mailing list