New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[subinterpreters] atexit module should not be loaded more than once per interpreter #84468
Comments
Since Python 3.7, it's possible to load the atexit module more than once: commit 776407f
Each new import executes the module which overrides PyInterpreterState.pyexitfunc with _Py_PyAtExit(). Example: import sys
atexit1 = sys.modules.pop('atexit', None)
if atexit1 is None:
import atexit as atexit1
del sys.modules['atexit']
import atexit as atexit2
atexit1.register(print, "atexit1 callback")
atexit2.register(print, "atexit2 callback") Output: Either PyInterpreterState should support a list of exit functions, or atexit should raise an exception if it's loaded more than once. call_ll_exitfuncs() calls a list of functions: _PyRuntimeState.exitfuncs. But these functions are called at the end of Py_Finalize(), whereas atexit functions are called after calling threading._shutdown() in Py_Finalize() and Py_EndInterpreter(). |
I will take a look :) |
I created bpo-40600: "Add an option to disallow creating more than one instance of a module". |
@vstineer |
I would prefer a more generic solution, if possible:
|
Fixed by bpo-42639. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: