[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-15 Thread STINNER Victor
STINNER Victor added the comment: > Thanks! Indeed, that's an even better solution than I had in mind. > It follows PEP 630 quite nicely: > https://www.python.org/dev/peps/pep-0630/#managing-global-state The atexit module was my main motivation for this issue. So I'm fine with closing it.

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-15 Thread Petr Viktorin
Petr Viktorin added the comment: Thanks! Indeed, that's an even better solution than I had in mind. It follows PEP 630 quite nicely: https://www.python.org/dev/peps/pep-0630/#managing-global-state I will close this issue and PRs. I don't agree with adding a general API for disallowing

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-14 Thread STINNER Victor
STINNER Victor added the comment: I created bpo-42639 and PR 23763 to move the atexit module to PyInterpreterState and so allow to have more than one atexit instance. -- ___ Python tracker

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-14 Thread STINNER Victor
Change by STINNER Victor : -- pull_requests: +22619 pull_request: https://github.com/python/cpython/pull/23763 ___ Python tracker ___

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-08 Thread hai shi
hai shi added the comment: > another solution is to move the "module state" into the interpreter, OK, I am agree victor's solution too. It's a more simpler way. -- ___ Python tracker

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-08 Thread Dong-hee Na
Change by Dong-hee Na : -- pull_requests: +22566 pull_request: https://github.com/python/cpython/pull/23699 ___ Python tracker ___

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-08 Thread Dong-hee Na
Dong-hee Na added the comment: > another solution is to move the "module state" into the interpreter, I am +1 on this solution if this module is a very special case. -- ___ Python tracker

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-08 Thread STINNER Victor
STINNER Victor added the comment: I'm not 100% sure that preventing to create multiple module instances is needed. For the atexit module, another solution is to move the "module state" into the interpreter, as it has been done for other modules like _warnings. --

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-08 Thread Petr Viktorin
Petr Viktorin added the comment: Are there any other examples? In my view, atexit is very special, and very closely tied to interpreter. I don't think it's good to design general API for one module. -- ___ Python tracker

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-08 Thread STINNER Victor
STINNER Victor added the comment: > static int loaded = 0; I would like to limit an extension to once instance *per interpreter*. See the atexit module for an example. -- ___ Python tracker

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-08 Thread Petr Viktorin
Petr Viktorin 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

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-07 Thread hai shi
hai shi added the comment: > MAYBE we need add a module flag in `PyModuleDef`. I created a demo in PR 23683. -- ___ Python tracker ___

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-07 Thread hai shi
Change by hai shi : -- keywords: +patch pull_requests: +22547 stage: test needed -> patch review pull_request: https://github.com/python/cpython/pull/23683 ___ Python tracker

[issue40600] Add option to disallow > 1 instance of an extension module

2020-12-07 Thread hai shi
hai shi added the comment: >On the other side, defining a Py_mod_exec_once that supports execution > >for >just once can be a way. >Although the usage is little, it will be fine because the use case will >exist. IMHO, `Py_mod_exec_once` is more like a slot control flag. MAYBE we need add a

[issue40600] Add option to disallow > 1 instance of an extension module

2020-11-19 Thread hai shi
Change by hai shi : -- nosy: +shihai1991 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue40600] Add option to disallow > 1 instance of an extension module

2020-09-10 Thread mohamed koubaa
mohamed koubaa added the comment: Something like this? ``` static PyObject *def; PyMODINIT_FUNC PyInit_mymod(void) { if (def == NULL) { def = PyModuleDef_Init(); } return def; } ``` Then add a flag to PyModuleDef to indicate it is already exec? --

[issue40600] Add option to disallow > 1 instance of an extension module

2020-09-10 Thread STINNER Victor
STINNER Victor added the comment: One option is to get the behavior before multi-phase initialization. We store extensions in a list. Once it's load, it cannot be unloaded before we exit Python. See _PyState_AddModule() and _PyState_AddModule(). Calling PyInit_xxx() the second time would

[issue40600] Add option to disallow > 1 instance of an extension module

2020-09-10 Thread Dong-hee Na
Dong-hee Na added the comment: One of my opinions is that Since module object supports detecting error during Py_mod_exec, The only thing we have to do is return -1 when the module has already existed. we should define new exception type and don't have to define new slots. The pros of this

[issue40600] Add option to disallow > 1 instance of an extension module

2020-09-07 Thread mohamed koubaa
mohamed koubaa added the comment: What about a new PyModuleDef_Slot function? ``` static int my_can_create(/*need any arg??, InterpreterState, etc?*/) { if (test_global_condition()) { return -1; //Don't allow creation } return 0; //Allow creation }; static

[issue40600] Add option to disallow > 1 instance of an extension module

2020-05-18 Thread STINNER Victor
Change by STINNER Victor : -- components: +Subinterpreters ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue40600] Add option to disallow > 1 instance of an extension module

2020-05-15 Thread Terry J. Reedy
Terry J. Reedy added the comment: Title clarified. Leaving subinterpreters aside, only one instance, AFAIK, is true for stdlib and python modules unless imported with different names, as can happen with main module (which is a nuisance if not a bug). So only once per interpreter seems