Author vstinner
Recipients corona10, vstinner
Date 2020-04-15.02:16:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1586917009.7.0.806642420762.issue40288@roundup.psfhosted.org>
In-reply-to
Content
Since Python 3.7, it's possible to load the atexit module more than once:

commit 776407fe893fd42972c7e3f71423d9d86741d07c
Author: Marcel Plch <gmarcel.plch@gmail.com>
Date:   Wed Dec 20 11:17:58 2017 +0100

    bpo-31901: atexit callbacks should be run at subinterpreter shutdown (#4611)
    
    Change atexit behavior and PEP-489 multiphase init support.

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:
---
atexit2 callback
---

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().
History
Date User Action Args
2020-04-15 02:16:49vstinnersetrecipients: + vstinner, corona10
2020-04-15 02:16:49vstinnersetmessageid: <1586917009.7.0.806642420762.issue40288@roundup.psfhosted.org>
2020-04-15 02:16:49vstinnerlinkissue40288 messages
2020-04-15 02:16:49vstinnercreate