New submission from STINNER Victor <vstin...@python.org>:
In Python 2.7, atexit was implemented in Python and registered itself using sys.exitfunc public attribute: https://docs.python.org/2.7/library/sys.html#sys.exitfunc https://docs.python.org/2.7/library/atexit.html#module-atexit In Python 3.0, the atexit module was rewritten in C. A new private _Py_PyAtExit() function was added to set a new private global "pyexitfunc" variable: variable used by call_py_exitfuncs() called by Py_Finalize(). In Python 3.7, the global "pyexitfunc" variable was moved int _PyRuntimeState (commit 2ebc5ce42a8a9e047e790aefbf9a94811569b2b6), and then into PyInterpreterState (commit 776407fe893fd42972c7e3f71423d9d86741d07c). In Python 3.7, the atexit module was upgrade to the multiphase initialization API (PEP 489): PyInit_atexit() uses PyModuleDef_Init(). Since Python 2.7, the atexit module has a limitation: if a second instance is created, the new instance overrides the old one, and old registered callbacks are newer called. One option is to disallow creating a second instance: see bpo-40600 and PR 23699 for that. Another option is to move the atexit state (callbacks) into PyInterpreterState. Two atexit module instances would modify the same list of callbacks. In this issue, I propose to investigate this option. ---------- components: Library (Lib) messages: 382982 nosy: vstinner priority: normal severity: normal status: open title: Make atexit state per interpreter versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42639> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com