summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-01-22 22:22:20 (GMT)
committerGitHub <noreply@github.com>2022-01-22 22:22:20 (GMT)
commit9c8e490b8f9e40a6fe9815be58bacaecab5369ee (patch)
treec249f59c3fb54dc2efb8c38c53b617f72b02c67e /Python/pylifecycle.c
parent1626bf4ac7aef1244e6f886e63a31f7ed65fbd10 (diff)
downloadcpython-9c8e490b8f9e40a6fe9815be58bacaecab5369ee.zip
cpython-9c8e490b8f9e40a6fe9815be58bacaecab5369ee.tar.gz
cpython-9c8e490b8f9e40a6fe9815be58bacaecab5369ee.tar.bz2
bpo-46417: Clear _io module static objects at exit (GH-30807)
Add _PyIO_Fini() function, called by finalize_interp_clear(). It clears static objects used by the _io extension module.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 7fc9d3c..92c8ad0 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -29,6 +29,8 @@
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
#include "pycore_unicodeobject.h" // _PyUnicode_InitTypes()
+extern void _PyIO_Fini(void);
+
#include <locale.h> // setlocale()
#include <stdlib.h> // getenv()
@@ -1702,6 +1704,10 @@ finalize_interp_clear(PyThreadState *tstate)
/* Clear interpreter state and all thread states */
_PyInterpreterState_Clear(tstate);
+ if (is_main_interp) {
+ _PyIO_Fini();
+ }
+
/* Clear all loghooks */
/* Both _PySys_Audit function and users still need PyObject, such as tuple.
Call _PySys_ClearAuditHooks when PyObject available. */