<rdar://problem/11862570> Fixing a potential crasher related to Python locking

git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@161054 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Interpreter/ScriptInterpreterPython.cpp b/source/Interpreter/ScriptInterpreterPython.cpp
index e1aa378..51f4af7 100644
--- a/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/source/Interpreter/ScriptInterpreterPython.cpp
@@ -367,7 +367,7 @@
                     StreamString run_string;
                     char error_str[1024];
                     const char *pty_slave_name = script_interpreter->m_embedded_python_pty.GetSlaveName (error_str, sizeof (error_str));
-                    if (pty_slave_name != NULL)
+                    if (pty_slave_name != NULL && PyThreadState_GetDict() != NULL)
                     {
                         run_string.Printf ("run_one_line (%s, 'save_stderr = sys.stderr')", script_interpreter->m_dictionary_name.c_str());
                         PyRun_SimpleString (run_string.GetData());
@@ -474,7 +474,7 @@
             StreamString run_string;
             char error_str[1024];
             const char *pty_slave_name = script_interpreter->m_embedded_python_pty.GetSlaveName (error_str, sizeof (error_str));
-            if (pty_slave_name != NULL)
+            if (pty_slave_name != NULL && PyThreadState_GetDict() != NULL)
             {
                 run_string.Printf ("run_one_line (%s, 'sys.stdin = save_stdin')", script_interpreter->m_dictionary_name.c_str());
                 PyRun_SimpleString (run_string.GetData());