summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-12-15 13:34:19 (GMT)
committerGitHub <noreply@github.com>2020-12-15 13:34:19 (GMT)
commitb8fa135908d294b350cdad04e2f512327a538dee (patch)
tree25b6b1516e3f6d29c9cf3cafb71c516cbc93a3c3 /Python/pylifecycle.c
parent8473cf89bdbf2cb292b39c972db540504669b9cd (diff)
downloadcpython-b8fa135908d294b350cdad04e2f512327a538dee.zip
cpython-b8fa135908d294b350cdad04e2f512327a538dee.tar.gz
cpython-b8fa135908d294b350cdad04e2f512327a538dee.tar.bz2
bpo-42639: Move atexit state to PyInterpreterState (GH-23763)
* Add _PyAtExit_Call() function and remove pyexitfunc and pyexitmodule members of PyInterpreterState. The function logs atexit callback errors using _PyErr_WriteUnraisableMsg(). * Add _PyAtExit_Init() and _PyAtExit_Fini() functions. * Remove traverse, clear and free functions of the atexit module. Co-authored-by: Dong-hee Na <donghee.na@python.org>
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 7b80d01..8d744c7 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -55,7 +55,6 @@ static PyStatus add_main_module(PyInterpreterState *interp);
static PyStatus init_import_site(void);
static PyStatus init_set_builtins_open(void);
static PyStatus init_sys_streams(PyThreadState *tstate);
-static void call_py_exitfuncs(PyThreadState *tstate);
static void wait_for_thread_shutdown(PyThreadState *tstate);
static void call_ll_exitfuncs(_PyRuntimeState *runtime);
@@ -690,6 +689,12 @@ pycore_init_types(PyThreadState *tstate)
if (_PyWarnings_InitState(tstate) < 0) {
return _PyStatus_ERR("can't initialize warnings");
}
+
+ status = _PyAtExit_Init(tstate);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+
return _PyStatus_OK();
}
@@ -1655,7 +1660,7 @@ Py_FinalizeEx(void)
* the threads created via Threading.
*/
- call_py_exitfuncs(tstate);
+ _PyAtExit_Call(tstate);
/* Copy the core config, PyInterpreterState_Delete() free
the core config memory */
@@ -1946,7 +1951,7 @@ Py_EndInterpreter(PyThreadState *tstate)
// Wrap up existing "threading"-module-created, non-daemon threads.
wait_for_thread_shutdown(tstate);
- call_py_exitfuncs(tstate);
+ _PyAtExit_Call(tstate);
if (tstate != interp->tstate_head || tstate->next != NULL) {
Py_FatalError("not the last thread");
@@ -2633,15 +2638,6 @@ Py_ExitStatusException(PyStatus status)
}
-/* Clean up and exit */
-
-static void
-call_py_exitfuncs(PyThreadState *tstate)
-{
- _PyAtExit_Call(tstate->interp->atexit_module);
-}
-
-
/* Wait until threading._shutdown completes, provided
the threading module was imported in the first place.
The shutdown routine will wait until all non-daemon