summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/ScriptInterpreterPython.cpp
diff options
context:
space:
mode:
authorCaroline Tice <ctice@apple.com>2011-03-11 00:21:55 +0000
committerCaroline Tice <ctice@apple.com>2011-03-11 00:21:55 +0000
commitc288e8ca0cedc08c58cf26d67d38ff167515387f (patch)
tree02060d8c7b984f55752f610b0a48891a57650439 /lldb/source/Interpreter/ScriptInterpreterPython.cpp
parent2d799cca03a4bef8672d6af624e16fa02696dc0c (diff)
downloadbcm5719-llvm-c288e8ca0cedc08c58cf26d67d38ff167515387f.tar.gz
bcm5719-llvm-c288e8ca0cedc08c58cf26d67d38ff167515387f.zip
Add some explanatory comments.
llvm-svn: 127438
Diffstat (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp')
-rw-r--r--lldb/source/Interpreter/ScriptInterpreterPython.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
index 68c120d451c..07eeafac0c2 100644
--- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
@@ -1384,6 +1384,17 @@ ScriptInterpreterPython::RunEmbeddedPythonInterpreter (lldb::thread_arg_t baton)
// The following call drops into the embedded interpreter loop and stays there until the
// user chooses to exit from the Python interpreter.
+ // When in the embedded interpreter, the user can call arbitrary system and Python stuff, which may require
+ // the ability to run multi-threaded stuff, so we need to surround the call the the embedded interpreter with
+ // calls to Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS.
+
+ // We ALSO need to surround the call to the embedded interpreter with calls to PyGILState_Ensure and
+ // PyGILState_Release. This is because this embedded interpreter is being run on a DIFFERENT THREAD than
+ // the thread on which the call to Py_Initialize (and PyEval_InitThreads) was called. Those initializations
+ // called PyGILState_Ensure on *that* thread, but it also needs to be called on *this* thread. Otherwise,
+ // if the user calls Python code that does threading stuff, the interpreter state will be off, and things could
+ // hang (it's happened before).
+
Py_BEGIN_ALLOW_THREADS
PyGILState_STATE gstate = PyGILState_Ensure();
OpenPOWER on IntegriCloud