[issue40600] Add option to disallow > 1 instance of an extension module
Petr Viktorin
report at bugs.python.org
Tue Dec 8 08:52:42 EST 2020
Petr Viktorin <encukou at gmail.com> added the comment:
Is it really necessary to add a slot/flag for this?
It can be done in about 10 lines as below, without complications like a global (or per-interpreter) registry of singleton modules.
Are there many modules that need to be per-interpreter singletons, but may be loaded in multiple interpreters? In my experience, it is really hard to ensure modules behave that way; if (if!) we need to add a dedicated API for this, I'd go for once-per-process.
static int loaded = 0;
static int
exec_module(PyObject* module)
{
if (loaded) {
PyErr_SetString(PyExc_ImportError,
"cannot load module more than once per process");
return -1;
}
loaded = 1;
// ... rest of initialization
}
----------
nosy: +petr.viktorin
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40600>
_______________________________________
More information about the Python-bugs-list
mailing list