diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 16 | ||||
-rw-r--r-- | Python/pylifecycle.c | 11 |
2 files changed, 17 insertions, 10 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index ccd0427a14..5480fbacaf 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -188,20 +188,26 @@ PyEval_InitThreads(void) } } + void _PyEval_FiniThreads(void) { + if (_PyRuntime.ceval.pending.lock != NULL) { + PyThread_free_lock(_PyRuntime.ceval.pending.lock); + _PyRuntime.ceval.pending.lock = NULL; + } +} + + +void +_PyEval_FiniThreads2(void) +{ if (!gil_created()) { return; } destroy_gil(); assert(!gil_created()); - - if (_PyRuntime.ceval.pending.lock != NULL) { - PyThread_free_lock(_PyRuntime.ceval.pending.lock); - _PyRuntime.ceval.pending.lock = NULL; - } } static inline void diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index d93fe06555..0836e18f9d 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; } |