diff options
author | Tatyana Krasnukha <tatyana@synopsys.com> | 2019-03-06 17:27:40 +0000 |
---|---|---|
committer | Tatyana Krasnukha <tatyana@synopsys.com> | 2019-03-06 17:27:40 +0000 |
commit | 1b6700eff4a928ea2f01fe74f9f902d9324e2551 (patch) | |
tree | 2a3cfbb4a55f58ce2feaa784773b1f4c1a915a4f /lldb/source/Plugins/ScriptInterpreter/Python | |
parent | 2391bfca97290181ae65796ea6da135d1b6d037b (diff) | |
download | bcm5719-llvm-1b6700eff4a928ea2f01fe74f9f902d9324e2551.tar.gz bcm5719-llvm-1b6700eff4a928ea2f01fe74f9f902d9324e2551.zip |
Re-apply "Fix embedded Python initialization according to changes in version 3.7"
llvm-svn: 355523
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index d1cd3ae5681..53e98c310f1 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -156,7 +156,7 @@ public: if (m_was_already_initialized) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT)); LLDB_LOGV(log, "Releasing PyGILState. Returning to state = {0}locked", - m_was_already_initialized == PyGILState_UNLOCKED ? "un" : ""); + m_gil_state == PyGILState_UNLOCKED ? "un" : ""); PyGILState_Release(m_gil_state); } else { // We initialized the threads in this function, just unlock the GIL. @@ -180,6 +180,18 @@ private: } void InitializeThreadsPrivate() { +// Since Python 3.7 `Py_Initialize` calls `PyEval_InitThreads` inside itself, +// so there is no way to determine whether the embedded interpreter +// was already initialized by some external code. `PyEval_ThreadsInitialized` +// would always return `true` and `PyGILState_Ensure/Release` flow would be +// executed instead of unlocking GIL with `PyEval_SaveThread`. When +// an another thread calls `PyGILState_Ensure` it would get stuck in deadlock. +#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 7) || (PY_MAJOR_VERSION > 3) +// The only case we should go further and acquire the GIL: it is unlocked. + if (PyGILState_Check()) + return; +#endif + if (PyEval_ThreadsInitialized()) { Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SCRIPT)); |