#include "Python.h"
#include "pycore_atexit.h"
#include "pycore_initconfig.h"
#include "pycore_interp.h"
#include "pycore_pystate.h"
static inline struct atexit_state*
get_atexit_state(void)
{ … }
int
PyUnstable_AtExit(PyInterpreterState *interp,
atexit_datacallbackfunc func, void *data)
{ … }
static void
atexit_delete_cb(struct atexit_state *state, int i)
{ … }
static void
atexit_cleanup(struct atexit_state *state)
{ … }
PyStatus
_PyAtExit_Init(PyInterpreterState *interp)
{ … }
void
_PyAtExit_Fini(PyInterpreterState *interp)
{ … }
static void
atexit_callfuncs(struct atexit_state *state)
{ … }
void
_PyAtExit_Call(PyInterpreterState *interp)
{ … }
PyDoc_STRVAR(atexit_register__doc__,
"register($module, func, /, *args, **kwargs)\n\
--\n\
\n\
Register a function to be executed upon normal program termination\n\
\n\
func - function to be called at exit\n\
args - optional arguments to pass to func\n\
kwargs - optional keyword arguments to pass to func\n\
\n\
func is returned to facilitate usage as a decorator.");
static PyObject *
atexit_register(PyObject *module, PyObject *args, PyObject *kwargs)
{ … }
PyDoc_STRVAR(atexit_run_exitfuncs__doc__,
"_run_exitfuncs($module, /)\n\
--\n\
\n\
Run all registered exit functions.\n\
\n\
If a callback raises an exception, it is logged with sys.unraisablehook.");
static PyObject *
atexit_run_exitfuncs(PyObject *module, PyObject *unused)
{ … }
PyDoc_STRVAR(atexit_clear__doc__,
"_clear($module, /)\n\
--\n\
\n\
Clear the list of previously registered exit functions.");
static PyObject *
atexit_clear(PyObject *module, PyObject *unused)
{ … }
PyDoc_STRVAR(atexit_ncallbacks__doc__,
"_ncallbacks($module, /)\n\
--\n\
\n\
Return the number of registered exit functions.");
static PyObject *
atexit_ncallbacks(PyObject *module, PyObject *unused)
{ … }
PyDoc_STRVAR(atexit_unregister__doc__,
"unregister($module, func, /)\n\
--\n\
\n\
Unregister an exit function which was previously registered using\n\
atexit.register\n\
\n\
func - function to be unregistered");
static PyObject *
atexit_unregister(PyObject *module, PyObject *func)
{ … }
static PyMethodDef atexit_methods[] = …;
PyDoc_STRVAR(atexit__doc__,
"allow programmer to define multiple exit functions to be executed\n\
upon normal program termination.\n\
\n\
Two public functions, register and unregister, are defined.\n\
");
static PyModuleDef_Slot atexitmodule_slots[] = …;
static struct PyModuleDef atexitmodule = …;
PyMODINIT_FUNC
PyInit_atexit(void)
{ … }