diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-04-29 09:15:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-29 09:15:56 (GMT) |
commit | b36e5d627d4232a01850707eb78a5067f3fd77f4 (patch) | |
tree | 63eb8a0966e7ac1b721f8de5c877d4bc79c6fa58 /Python/pylifecycle.c | |
parent | 7a5a1cfe04892351bba8e8d7d21ae2262fa35b67 (diff) | |
download | cpython-b36e5d627d4232a01850707eb78a5067f3fd77f4.zip cpython-b36e5d627d4232a01850707eb78a5067f3fd77f4.tar.gz cpython-b36e5d627d4232a01850707eb78a5067f3fd77f4.tar.bz2 |
bpo-36356: Destroy the GIL at exit (GH-12453)
* Add _PyEval_FiniThreads2(). _PyEval_FiniThreads() now only clears
the pending lock, whereas _PyEval_FiniThreads2() destroys the GIL.
* pymain_free() now calls _PyEval_FiniThreads2().
* Py_FinalizeEx() now calls _PyEval_FiniThreads().
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r-- | Python/pylifecycle.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index d93fe06..0836e18 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -4,8 +4,9 @@ #include "Python-ast.h" #undef Yield /* undefine macro conflicting with <winbase.h> */ -#include "pycore_coreconfig.h" +#include "pycore_ceval.h" /* _PyEval_FiniThreads() */ #include "pycore_context.h" +#include "pycore_coreconfig.h" #include "pycore_fileutils.h" #include "pycore_hamt.h" #include "pycore_pathconfig.h" @@ -555,12 +556,11 @@ pycore_create_interpreter(_PyRuntimeState *runtime, return _Py_INIT_ERR("can't make first thread"); (void) PyThreadState_Swap(tstate); - /* We can't call _PyEval_FiniThreads() in Py_FinalizeEx because - destroying the GIL might fail when it is being referenced from - another running thread (see issue #9901). + /* Destroying the GIL in Py_FinalizeEx might fail when it is being + referenced from another running thread (see bpo-9901). Instead we destroy the previously created GIL here, which ensures that we can call Py_Initialize / Py_FinalizeEx multiple times. */ - _PyEval_FiniThreads(); + _PyEval_FiniThreads2(); /* Auto-thread-state API */ _PyGILState_Init(runtime, interp, tstate); @@ -1357,6 +1357,7 @@ Py_FinalizeEx(void) call_ll_exitfuncs(runtime); + _PyEval_FiniThreads(); _PyRuntime_Finalize(); return status; } |